Merge branch 'master' of github.com:johnbintz/formtastic-slug
This commit is contained in:
commit
ca7111edac
|
@ -6,6 +6,14 @@ Add a slug field, that generates a slug based on another field.
|
||||||
= f.input :slug, :as => :slug, :based_on => :title
|
= f.input :slug, :as => :slug, :based_on => :title
|
||||||
```
|
```
|
||||||
|
|
||||||
|
You can put in the list of existing slugs and the editor will avoid using those:
|
||||||
|
|
||||||
|
``` haml
|
||||||
|
= semantic_form_for @blog_entry do |f|
|
||||||
|
= f.input :title
|
||||||
|
= f.input :slug, :as => :slug, :based_on => :title, :existing_slugs => @blog_entry.class.slugs
|
||||||
|
```
|
||||||
|
|
||||||
Just add it to your Gemfile:
|
Just add it to your Gemfile:
|
||||||
|
|
||||||
``` ruby
|
``` ruby
|
||||||
|
|
|
@ -34,6 +34,10 @@ class SlugInput < Formtastic::Inputs::StringInput
|
||||||
target_method_name.to_s.gsub(/[\?\/\-]$/, '')
|
target_method_name.to_s.gsub(/[\?\/\-]$/, '')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def existing_slugs
|
||||||
|
options[:existing_slugs] || []
|
||||||
|
end
|
||||||
|
|
||||||
def slug_js_setup
|
def slug_js_setup
|
||||||
(<<-JS).html_safe
|
(<<-JS).html_safe
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
@ -41,7 +45,7 @@ class SlugInput < Formtastic::Inputs::StringInput
|
||||||
var targetField = $('##{target_dom_id}');
|
var targetField = $('##{target_dom_id}');
|
||||||
var slugField = $('##{dom_id}');
|
var slugField = $('##{dom_id}');
|
||||||
var slugInputWrap = $('##{dom_id}_input');
|
var slugInputWrap = $('##{dom_id}_input');
|
||||||
var existingSlugs = #{options[:existing_slugs].to_json}
|
var existingSlugs = #{existing_slugs.to_json};
|
||||||
var startingSlug = slugField.val();
|
var startingSlug = slugField.val();
|
||||||
|
|
||||||
var setSlug = function(text) {
|
var setSlug = function(text) {
|
||||||
|
|
Loading…
Reference in New Issue