One of my prevois project, I needed to populate product catalogs in second select box depends on the product selected in first select box in active admin input form. I implemented this by refering one of the example by @abidsm in his github repo.
Implementation
First we need to add dependent_select.js file.
Now we need to add logic tocatalogs_product.rb in admin folder.
catalogs_product.rb
Here ‘data-option-dependent’ => true will bind depentent select js to catalog input field.
‘data-option-observed’ => ‘catalogs_product_product_id’ specify that, the catalog field is depending on input in product field. catalogs_product_product_id is the id of the product field in this form.
Now we need to specify the json method which will populate catalogs data depends on the product is selected in parent input select.
‘data-option-url’ => ‘/products/:catalogs_product_product_id/catalogs’
Now we need to add index method with json output in catelogs controller.catalogs_controller.rb
routes.rb
That’s it now you can see catalog select box will be repopulated when we select a product in product select box. This can be implemented in any of formastic input forms.
Implementation
First we need to add dependent_select.js file.
Now we need to add logic to
1 2 3 4 5 6 7 8 9 |
|
‘data-option-observed’ => ‘catalogs_product_product_id’ specify that, the catalog field is depending on input in product field. catalogs_product_product_id is the id of the product field in this form.
Now we need to specify the json method which will populate catalogs data depends on the product is selected in parent input select.
‘data-option-url’ => ‘/products/:catalogs_product_product_id/catalogs’
Now we need to add index method with json output in catelogs controller.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
1 2 3 4 5 6 |
|