Question

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.

Was it helpful?

Solution

The correct syntax is:

f.input :date, :as => 'date_picker', :input_html => { :data => {:datepicker => :datepicker} }

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top