Reputation: 196
I'm using simple_form in Rails 4, and I was using an input that I then passed data attributes to like so:
<%= f.input :url, :input_html => {"data-toggle" => "tooltip", :title => "My tooltip"} %>
and it worked as expected, creating tags like:
<input data-toggle="tooltip" data-original-title="My tooltip">
Now, however, I need to use simple_form's input_field
so I can have more control over the display, but it doesn't seem to accept the input_html argument. My code looks like:
<%= f.input_field :url, :input_html => {"data-toggle" => "tooltip", :title => "My tooltip"} %>
and it results in:
<input html="{:data=>{"data-toggle"=>"tooltip", :title=>"My tooltip"}}">
Which is clearly suboptimal (I stripped other irrelevant properties and attributes to simplify). Any ideas on how to make this work?
Upvotes: 1
Views: 331
Reputation: 2293
Looking at the code for SimpleForm::FormBuilder#input_field, it appears that all options passed in are treated as if they were under :input_html
.
Try removing :input_html
and just passing the options directly:
<%= f.input_field :url, "data-toggle" => "tooltip", :title => "My tooltip" %>
Upvotes: 2