简体   繁体   中英

Filter the Dropdown Input in ActiveAdmin Rails

So I have a Company, Subcompany models, and I use the Brand model as the masterlist for all company and subcompanies. Right now, when the admin user creates a new company, they have to use the dropdown list of brands to put a new company or subcompany into the list.

This becomes unscalable as there are 10000's of companies. The easiest way to filter out companies is to filter by category. so assuming all brands have a category attribute, I was wondering if there is any way, within the ActiveAdmin framework, to allow the admin user to filter the dropdown list by a category?

Here is what I have so far, it allows me to do a drop down on all the brands. But I want a way for the user to dynamically shrink the list by picking a category.

  form do |f|
    f.inputs do
      f.input :name, :as => :select, :collection => Brand.all.collect {|brand| brand.name }
      f.has_many :sub_companies, allow_destroy: true do |sub|
        sub.input :name, :as => :select, :collection => Brand.all.collect {|brand| brand.name}
      end
    end
    actions
  end

There is no build in way, you can do one of the following thinks:

  1. User select2, a suggest/search supporting select field, you can find some integration help here

  2. You can write a javascript to fill a second select by the value of the first one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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