Merge branch 'master' of github.com:johnbintz/formtastic-slug

This commit is contained in:
John Bintz 2013-04-03 07:04:53 -04:00
commit ca7111edac
2 changed files with 13 additions and 1 deletions

View File

@ -6,6 +6,14 @@ Add a slug field, that generates a slug based on another field.
= 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:
``` ruby

View File

@ -34,6 +34,10 @@ class SlugInput < Formtastic::Inputs::StringInput
target_method_name.to_s.gsub(/[\?\/\-]$/, '')
end
def existing_slugs
options[:existing_slugs] || []
end
def slug_js_setup
(<<-JS).html_safe
<script type="text/javascript">
@ -41,7 +45,7 @@ class SlugInput < Formtastic::Inputs::StringInput
var targetField = $('##{target_dom_id}');
var slugField = $('##{dom_id}');
var slugInputWrap = $('##{dom_id}_input');
var existingSlugs = #{options[:existing_slugs].to_json}
var existingSlugs = #{existing_slugs.to_json};
var startingSlug = slugField.val();
var setSlug = function(text) {