Muflix
Muflix

Reputation: 6768

Rails: how do I set ID or Name attribute in text_field_tag?

<%= text_field_tag :barcode, params[:barcode] %>

generates

<input id="barcode" name="barcode" type="text"></input>

but I need

<input type="text" name="barcode" id="autocomplete"></input>

But in the documentation I did not find a way how to change the ID attribute.

I need to use a text_field_tag because it fills the textbox with params if submit fails.

Upvotes: 11

Views: 24544

Answers (3)

HNpublic
HNpublic

Reputation: 51

Try this:

<%= text_field_tag "name_text","value_text", :class => "txBox", :size=>15 %>

HTML:

<input type="text" size="15" name="name_text" id="name_text" values="" class="txBox">

Upvotes: 1

amit karsale
amit karsale

Reputation: 755

You can also try this...

<%= text_field_tag :barcode, params[:barcode], :id => 'autocomplete' %>

Upvotes: 1

n_i_c_k
n_i_c_k

Reputation: 1534

try this

<%= text_field_tag :barcode, params[:barcode], id: 'autocomplete' %>

Upvotes: 27

Related Questions