D
D
dexdev2014-12-18 20:27:30
Ruby on Rails
dexdev, 2014-12-18 20:27:30

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]"

made the following form
<%= form_tag @sub_category, method: 'get' do |d| %>
<%= text_field_tag "ex2", type: "text", class: "span2" %>
<% end %>

here in
<%= text_field_tag "ex2", type: "text", class: "span2" %>
must be inserted
data-slider-min="10" data-slider-max="1000" data-slider-step="5" data-slider-value="[250,450]"

insert
%= 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]' } %>

displays
:data=>{"slider-id"=>"ex2", "slider-min"=>"0", "slider-max"=>"20", "slider-step"=>"1", "slider-value"=>"[250,450]"}}"

but something doesn't work.
And tell me how best to filter the output after submitting the form with range slider?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Krasnodemsky, 2014-12-19
@AdilA

= 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">

V
Viktor Vsk, 2014-12-19
@viktorvsk

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 question

Ask a Question

731 491 924 answers to any question