简体   繁体   English

ActiveAdmin将过滤器添加到表单

[英]ActiveAdmin add filter to form

I have some properties on an active admin model, which can have a LOT of different values, so right now I'm displaying them using checkboxes: 我在一个主动管理模型上具有一些属性,该模型可以具有很多不同的值,所以现在我使用复选框来显示它们:

  PropertyType.find_each do |pt|
    f.input :property_values
    f.input :property_values, label: pt.display_name,  as: :check_boxes, collection: pt.property_values.order(name: :asc, display_name: :asc).load , multiple: true
  end

What I would like to do is to add an input field, in which while i'm writing, it filters the whole checkboxes list, only displaying the ones that matches the input field. 我想做的是添加一个输入字段,在我编写时,它会过滤整个复选框列表,仅显示与输入字段匹配的复选框。

Is there a way to do that? 有没有办法做到这一点?

Thanks. 谢谢。

Yes. 是。 Check out chosen_rails gem . selected_rails gem

In active_admin it will look something like this: 在active_admin中,它将如下所示:

f.input :property_values,
  label: pt.display_name,
  as: :check_boxes,
  collection: pt.property_values.order(name: :asc, display_name: :asc).load,
  input_html: { class: 'chosen-select' },
  multiple: true

The only thing I haven't tried it with check_boxes, but with as: :select , and it works perfectly. 唯一没有用check_boxes尝试过的东西,而是使用as: :select ,它运行完美。 I think select would be doing the same for you, since you have multiple: true 我认为select会为您做同样的事情,因为您有multiple: true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM