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?
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.
Text field tag
Try this:
<%= text_field_tag :street, '', :required => true %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With