Reputation: 1964
I would like to have an additional data attribute on an input tag generated by simple_form. The following does not work:
<%= f.input :date, :as => 'date_picker', :data => {:datepicker => :datepicker} %>
How could this be done? Is it possible at all? As you might have guessed: I am trying to add bootstrap-datepicker to my site without using explicit js to initialize the date picker.
Upvotes: 41
Views: 25991
Reputation: 3285
The correct API is:
f.input :date, :as => 'date_picker', :input_html => { :data => {:datepicker => :datepicker} }
Upvotes: 86
Reputation: 2036
For prosperity. On Rails 4.2.5 and Simple Form 3.2.1
The above from @rafaelfranca works for inputs:
f.input :first_name, input_html: { data: { cool_stuff: "yes" } }
If you want to add a data attribute to the simple_form_for helper:
simple_form_for @form, html: { data: { super_cool_key: "secret" } } do |f|
Note the difference: input_html:
vs html:
Also, the underscores will automatically get changed to a dash.
Upvotes: 10