Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Nested Select not filtering based on selection #484

Open
Andrew-Max opened this issue Oct 1, 2023 · 1 comment
Open

[BUG] Nested Select not filtering based on selection #484

Andrew-Max opened this issue Oct 1, 2023 · 1 comment
Labels

Comments

@Andrew-Max
Copy link

Andrew-Max commented Oct 1, 2023

Describe the bug
I've implemented a nested select and it all renders. But my the values in the second field are not scoped to the selection of the first field and if I look in the controller action that handles this, no ID is being passed to it at all to scope based off of

To Reproduce

class Order < ApplicationRecord
  belongs_to :shipping_address
  belongs_to :customer
class Customer < ApplicationRecord
  has_many :orders
  has_many :shipping_addresses
  accepts_nested_attributes_for :shipping_addresses
end
class ShippingAddress < ApplicationRecord
  has_many :orders
  belongs_to :customer
ActiveAdmin.register Order do
  form do |f|
    f.inputs "Customer" do
      f.input :nested_shipping_address,
              as: :nested_select,
              minimum_input_length: 0,
              level_1: {
                attribute: :customer,
              },
              level_2: {
                attribute: :shipping_address,
                display_name: :address_1,
              }
    end

When I bind in the controller that handles the index request, here are what the params look like:
=> #<ActionController::Parameters {"order"=>"name_desc", "q"=>{"groupings"=>{"0"=>{"m"=>"or", "name_cont"=>""}}, "combinator"=>"and", "customer_eq"=>"-1"}, "controller"=>"admin/shipping_addresses", "action"=>"index"} permitted: true>

Additional context
I've also been completely unable to figure out how to view the js in the browser or to try to figure out a way to monkey patch any of this. Open to suggestions on that if anyone know what to do.

@Andrew-Max Andrew-Max added the bug label Oct 1, 2023
@omar-mohamed
Copy link

@Andrew-Max I had a similar issue where this code didn't filter:

      f.input :customer_car, as: :nested_select,
                             display_name: :display_name,
                             minimum_input_length: 0,
                             level_1: {
                               attribute: :customer,
                               minimum_input_length: 1,
                               fields: %i[id name phone]
                             },
                             level_2: {
                               attribute: :customer_car,
                               fields: %i[id plate_number]
                             }

It also sent "customer_eq"=>"-1". I made it work by making the attribute in level 1 customer_id

      f.input :customer_car, as: :nested_select,
                             display_name: :display_name,
                             minimum_input_length: 0,
                             level_1: {
                               attribute: :customer_id,
                               minimum_input_length: 1,
                               fields: %i[id name phone]
                             },
                             level_2: {
                               attribute: :customer_car,
                               fields: %i[id plate_number]
                             }

This made the parameters like this:
{"order"=>"id_desc", "q"=>{"groupings"=>{"0"=>{"m"=>"or", "id_eq"=>"", "plate_number_cont"=>""}}, "combinator"=>"and", "customer_id_eq"=>"9"}, "customer_car"=>{}}

I'm on v2.0.0.beta.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants