gpt4 book ai didi

ruby-on-rails - 当设置默认值 : Disabled on a form, 时,一些 bool 选项被禁用?

转载 作者:太空宇宙 更新时间:2023-11-03 16:46:54 25 4
gpt4 key购买 nike

我有以下生成表单的行。调用时, Controller 在某些情况下将@disabled 设置为 true,在其他情况下设置为 false。

= simple_form_for [:applicant, @application ],defaults: { disabled: @disabled }, url: wizard_path, method: :put do |f|

在某些页面上,我有一个使用 bool 选项的选择语句。

= f.input :accommodation, as: :select, collection: yes_no

调用以下辅助函数作为集合

  def yes_no
[
['Yes', true ],
['No', false ]
]
end

当@disabled 设置为false 时,simple_form 去渲染false 选项,好像是禁用了。我不确定如何绕过这个 bool 值冲突以在下拉列表中生成 true 和 false 选项,同时还允许 @disabled 禁用整个表单(如果适用)

最佳答案

SimpleForm 和 Rails 之间的已知问题:https://github.com/plataformatec/simple_form/issues/1257

tonywok 的回答目前似乎是一个有效的解决方法:https://github.com/plataformatec/simple_form/issues/1257#issuecomment-119226834

改变

= simple_form_for [:applicant, @application ],defaults: { disabled: @disabled }, url: wizard_path, method: :put do |f|

= simple_form_for [:applicant, @application ],defaults: { disabled: @disabled, readonly: nil }, url: wizard_path, method: :put do |f|

关于ruby-on-rails - 当设置默认值 : Disabled on a form, 时,一些 bool 选项被禁用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31350734/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com