Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to set required attribute on text_field_tag?

In text_field one can do the following to set the required attribute.

< %= f.text_field :street, :required => true % >

< input id="recipe_name" name="recipe_name" type="text" required >

However, with text_field_tag, if I do the same the output html sets the value attribute instead, which is not correct.

< %= text_field_tag :street, :required => true % >

output:

< input id="recipe_name" name="recipe_name" type="text" value="{:required=>true}" >

Is required not supported in text_field_tag? What is a good way to work around it?

like image 692
HHC Avatar asked Oct 21 '13 06:10

HHC


2 Answers

Try: text_field_tag(name, value = nil, options = {})

<%= text_field_tag :street, nil, :required => true %>

When you provide options to the helper, you have to pass the value for value parameter.

like image 60
shweta Avatar answered Oct 27 '22 21:10

shweta


Text field tag

Try this:

<%= text_field_tag :street, '', :required => true %>
like image 21
Oleg Haidul Avatar answered Oct 27 '22 23:10

Oleg Haidul