platanus / activeadmin_addons

Extends ActiveAdmin to enable a set of great optional UX improving add-ons
MIT License
752 stars 282 forks source link

Use association name in selects #462

Closed difernandez closed 1 year ago

difernandez commented 1 year ago

Motivation / Background

Search and nested selects have to use the name of the id in order to work. This has the following drawbacks:

Closes #406

Detail

This Pull Request makes both selects work with the name of the association instead of the id. This is a breaking change. With these changes, this:

f.input :city_id, as: :nested_select,
                  level_1: { attribute: :country_id },
                  level_2: { attribute: :region_id },
                  level_3: { attribute: :city_id }
f.input :user_id, as: :search_select, display_name: :email, url: admin_users_path, fields: [:email]

becomes this:

f.input :city, as: :nested_select,
               level_1: { attribute: :country },
               level_2: { attribute: :region },
               level_3: { attribute: :city }
f.input :user, as: :search_select, display_name: :email, url: admin_users_path, fields: [:email]

To achieve this, these changes were done:

Extra Had to fix an error in an association in the dummy app

Additional information

Examples of inputs now showing validation errors

Given the search select input for required user:

f.input :user, as: :search_select, display_name: :email, url: admin_users_path, fields: [:email]

image

Given the nested input for required item:

f.input :item, as: :nested_select,
               level_1: { attribute: :brand },
               level_2: { attribute: :item }

image

Checklist

Before submitting the PR make sure the following are checked: