简体   繁体   中英

Rails Form: Placeholder Text Ignored

This line is in one of my forms:

<%= question.answer %><%= f.text_field :answer, :placeholder => "Respond..." %>

It displays the answer to a question and shows a text field to update that answer.

The only problem is that the place holder text is never shown and the content is always set to the answer content rather than "Respond..." as a placeholder.

Try this:

<%= question.answer %><%= f.text_field :answer, '', :placeholder => "Respond..." %>

You were setting your placeholder as the value parameter: text_field_tag(name, value = nil, options = {})

http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-text_field_tag

<%= question.answer %><%= f.text_field :answer, :value => "", :placeholder => "Respond..." %>

Does the trick it seems, this is a modified version of @Yogzzz's answer - he should get credit. He hasn't made the changes to his answer so I can't accept it as correct.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM