-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Polymorphic filter select #2886
Polymorphic filter select #2886
Conversation
753b48c
to
0146a3a
Compare
I'm pretty sure the remaining test failure isn't related to this PR. If you rebuild the failing one, it will most likely pass. |
3213f86
to
0146a3a
Compare
Just merged with master, so this is up to date and passing now. |
@shekibobo thank you for taking this code and updating it with newest master 🙇 I was going to update my fork and your work saved me a lot of time! @mshibuya can anything be done to help getting this merged to master? |
Thank you for this, i'm using it on my fork |
default_options = { float_left: false } | ||
|
||
js_data = type_collection.inject({}) do |options, model| | ||
model_name = model[0].downcase.parameterize.underscore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a model has a different label set in the locales the filtering will not work. Seems to break the lookup of the remote source for the filtering javascript widget.
I've changed the line to model_name = model.second.underscore.downcase
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why .second
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first string in the model
array is the model label that is displayed in the drop-down, the second string is the model class name used in the routing.
Eg. ["Car", "Vehicle"]
Until now, for polymorphic associations, a simple select tag was used, without filtering option. This commit adds filtering that easily works with switching association class. For each association class we need a path to load records from. For simple association, this is hardcoded in the `select` tag, for polymorphic one, we need to save them (a div with specific `data` attribute is generated) and switch whenever object type is switched. Switching type is a 3 step process: * update `data-options` attribute of select tag * destroy filtering object * create filtering object with new options Additionally, to avoid weird CSS behaviour, a fix to CSS generation was introduced. Without it, the object type field was moved to the right (since object value field had `float: left;` attribute set Use filter select for polymorphic association fields
5508737
to
8ad0793
Compare
What steps need to be taken to get this merged? |
Fantastic, thanks! |
This was adapted from #2461 and updates it to the latest master, along with a few other fixes.
Polymorphic associations are still
belongs_to
associations, so they should behave as much the same way as possible. Now, when we update the type field of a polymorphic association, we get a autocomplete field for the association record instead of it loading the entire collection (which causes browser lockup for extremely large collections).