pat*_*tie 57 ruby-on-rails erb simple-form ruby-on-rails-4
我试图做输入的默认值
工作正常:
<%= f.input_field :quantity, default: '1' %>
Run Code Online (Sandbox Code Playgroud)
但我需要f.input而不是f.input_field
<%= f.input :quantity %>
Run Code Online (Sandbox Code Playgroud)
我尝试使用标准的html值 - 但在不成功的验证数量被1覆盖 - 不需要的
<%= f.input :quantity, input_html: {value: '1'} %>
Run Code Online (Sandbox Code Playgroud)当我删除值和验证是不成功的数量填充 - 一切都很好
<%= f.input :quantity %>
Run Code Online (Sandbox Code Playgroud)怎么解决这个?有没有像f.input_field那样的选择 - :默认?还是有其他有价值的解决方案?
Ole*_*dul 135
你可以尝试这样的事情:
<%= f.input :quantity, input_html: {value: f.object.quantity || '1'} %>
Run Code Online (Sandbox Code Playgroud)
您可以使用selectedsimple_form 选项:
<%= f.input :quantity, selected: f.object.quantity || '1' %>
| 归档时间: |
|
| 查看次数: |
44690 次 |
| 最近记录: |