我有一个大 simple_form形式需要被启用或禁用取决于在窗体的部分被加载领域。simple_form:true或只读:无添加禁用禁用表单真实的每个输入
我的问题是:你怎么快速禁止任何形式的输入使用simple_form佣工/包装?
Simple Form's documentation解释如何disabled: true
可以用来禁用单一的输入场:
<%= simple_form_for @user do |f| %>
<%= f.input :username, disabled: true %>
<%= f.button :submit %>
<% end %>
但文档是我怎么能通过simple_form助手禁用整个形式,而无需重复不太清楚disabled: true
在字面上每个表单输入。
我尝试将disabled: true
和readonly: true
传递给simple_form的:wrapper_mappings
选项,但那不起作用。
例如代码:
我经由部分负荷的形式,以限定显示simple_form变量。这工作:
#user/show.html.erb:
<%= render partial: 'shared/form', locals: {questionnaire: @questionnaire, readonly_state: true, disabled_state: true, bootstrap_form_class: 'form-horizontal'} %>
然而, readonly_state和 disabled_state没有工作,除非我把它们传递给每一个表单输入:
# shared/_form.html.erb
<%= simple_form_for(@questionnaire, :html => {:class => bootstrap_form_class},
:wrapper_mappings => {check_boxes: :vertical_radio_and_checkboxes, file: :vertical_file_input,
boolean: :vertical_boolean }) do |f| %>
<%= f.input :username, disabled: disabled_state, hint: 'You cannot change your username.' %>
<%= f.input :email, disabled: disabled_state %>
<%= f.input :city, disabled: disabled_state %>
<%= f.input :country, disabled: disabled_state %>
. . .
<%= f.button :submit %>
<% end %>
你可以很快地看到重复这得到与一个大的形式。