Skip to content

Conversation

@pierrickouw
Copy link
Contributor

Thanks for the great lib!
We use it a lot in our application and found a small issue when using belongs_to in active admin.

-> To make belongs_to works with the lib, we have to add path_params in the ajax options (as described here). But this example doesn't work when the Model already have a value (it is not preselected). It works well for subsequent search.

-> This is because https://github.com/codevise/activeadmin-searchable_select/blob/master/lib/activeadmin/searchable_select/select_input_extension.rb#L87 is taking into account only the params and not the path_params during initial load.


In our code, to fix it we had to add it twice, which we guess is not intended:

            f.input(:option_value,
                    as: :searchable_select,
                    ajax: {
                      resource: OptionValue,
                      path_params: {
                        option_type_id: f.object.product.option_type_id
                      },
					 params: {
					  option_type_id: f.object.product.option_type_id
					}
                    })

cc @ChrLec

@tf
Copy link
Member

tf commented May 3, 2023

Sorry for the delay. Makes sense. Will publish a new version later today.

@tf tf merged commit 165cfc8 into codevise:master May 3, 2023
@tf tf mentioned this pull request May 3, 2023
@tf tf added this to the v1.7 milestone May 3, 2023
@tf
Copy link
Member

tf commented May 3, 2023

For some reason, GitHub did not trigger the test workflow for this PR. I therefore did not notice that the specs contained a syntax error (extra opening do here). Fixing that, I kept running into the error described in this commit. Did you see this locally? Moved the new spec to the end-to-end test to work around the problem in #44.

Released as 1.7.0.

@pierrickouw
Copy link
Contributor Author

Sorry for the typo, I guess it went in just before pushing, thanks for the merge!

glebtv pushed a commit to rs-pro/activeadmin-tom_select that referenced this pull request Aug 19, 2025
Fix pre-selected item when using belongs_to
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants