Rails: Attribute required for collection in simple_form

别来无恙 提交于 2020-01-07 03:04:34

问题


We are trying to set required in simple_form. The following setup does not work.

<%= f.input :payee_id, :label => t('Payee'), required: true, :collection => BankAccountx.payee_class.where(active: true).map {|x| [x.name, x.id]}, :selected => params[:payee_id], include_blank: true %>

Also tried :input_html => {required: true} and it did not work as well.

What's the right way to set required in simple_form?


回答1:


Found it. If you use this command:

rails generate simple_form:install

It will create a file at config/initializer/simple_form.rb. Find this line

config.browser_validations = false

And change it to true. NOTE: If you just add the gem and not run rails generate, it works by default.



来源:https://stackoverflow.com/questions/34235736/rails-attribute-required-for-collection-in-simple-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!