简体   繁体   English

Rails形式:占位符文本被忽略

[英]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. 唯一的问题是,占位符文本永远不会显示,并且内容始终设置为答案内容,而不是占位符“ Respond ...”。

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 = {}) 您正在将占位符设置为value参数:text_field_tag(name,value = nil,options = {})

http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-text_field_tag 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. 看起来有技巧,这是@Yogzzz答案的修改版本-他应该得到荣誉。 He hasn't made the changes to his answer so I can't accept it as correct. 他尚未更改答案,所以我不能接受它是正确的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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