【问题标题】:Conditional Show/Hide in Active Admin在活动管理员中条件显示/隐藏
【发布时间】:2015-03-18 16:59:08
【问题描述】:

我在 Active Admin 中有这个表格:

form(:html => { :multipart => true }) do |f|
  f.inputs 'Home Carousel Image' do
    f.input :name
    f.input :file, as: :file
    f.input :headline_text, as: :html_editor
    f.input :button_text
    f.input :featured_image?
    f.input :headline_text
    f.input :button_text
  end

  actions
end

精选图片?是一个布尔值。我希望看看用户是否选择了这个(将其切换为 true),然后才会显示 :headline_text 和 :button_text 的输入字段。否则,这两个字段将在表单中隐藏。

这可能吗?

谢谢

【问题讨论】:

    标签: ruby-on-rails forms activeadmin


    【解决方案1】:

    是的,只需使用if

    f.input :featured_image?
    if f.object.featured_image?
      f.input :headline_text
      f.input :button_text
    end
    

    使用f.object 获取模型的实例。

    【讨论】:

    • 感谢 maxd!出于某种原因,我不断收到参数错误?参数数量错误(1 代表 0)
    • 它在 Active Admin 模型中:ArgumentError in Admin::HomeCarousel
    • 好的,我只是让它通过而没有错误。但看起来该字段仅在您点击提交并返回后才会出现。看起来其他人尝试使用 proc?: :if => proc{ current_user.is_admin? }
    • 所以,我可以用一些 javascript / jquery 破解它。感谢 f.object 示例!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-04
    • 1970-01-01
    • 1970-01-01
    • 2020-11-21
    • 1970-01-01
    相关资源
    最近更新 更多