Answer the question
In order to leave comments, you need to log in
How to insert html attributes with "-" sign into text_field_tag?
I am making a range slider as a filter using bootstrap-slider, I don’t know how to insert values with a "-" sign into text_field_tag, I need to insert the following
data-slider-min="10" data-slider-max="1000" data-slider-step="5" data-slider-value="[250,450]"
<%= form_tag @sub_category, method: 'get' do |d| %>
<%= text_field_tag "ex2", type: "text", class: "span2" %>
<% end %>
<%= text_field_tag "ex2", type: "text", class: "span2" %>
must be inserteddata-slider-min="10" data-slider-max="1000" data-slider-step="5" data-slider-value="[250,450]"
%= text_field_tag "ex2", type: "text", class: "span2",data: {'slider-id' => 'ex2',
'slider-min' => '0',
'slider-max' => '20',
'slider-step' => '1',
'slider-value' => '[250,450]' } %>
:data=>{"slider-id"=>"ex2", "slider-min"=>"0", "slider-max"=>"20", "slider-step"=>"1", "slider-value"=>"[250,450]"}}"
Answer the question
In order to leave comments, you need to log in
= text_field_tag "prop[one]", nil, data: { slider-min: min, slider-max: max, slider-step: step, slider-value: value }, class: 'span2'
<input readonly="" class="span2" data-slider-max="5000" data-slider-min="800" data-slider-step="10" data-slider-value="250,450" id="" name="prop[one]" type="text">
Apparently, text_field_tag does not have special processing of the data parameter (which link_to and form_for have), and you need to write 'data-slider-min' => '0' yourself.
Advice in such cases, when something is not clear where it comes from - take it and do it without builders and other goodies: take it and stupidly write simple html. And how it works - then already figure out why it doesn’t work out beautifully.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question