-
-
Notifications
You must be signed in to change notification settings - Fork 352
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
Avoid double values when using horizontal=True #274
base: master
Are you sure you want to change the base?
Conversation
@leibowitz is this happening with the latest master version? |
Pretty sure since this part of the code hasn't been changed since this PR was created. I will make a test repo to illustrate when I get the time |
The main issue is not really the duplication of values, but more the double initialisation of the select. This seems to be due to the inline being initialised first with I can try to create another PR to fix the underlying issue. This one is more like a workaround to avoid the select filling up with duplicate values in the meantime |
Also worth noting the issue with
Don't forget to do this if you want to try it out |
@leibowitz I'm trying to reproduce this without success. Using current master, on the test-app, both Can you reproduce using the test-app? Thanks! |
Have you used both?
|
I tried with django 3.0.9 (latest as far as I can tell) And some older versions as well, and I cannot reproduce either... not sure how to explain this. This issue was a real issue I was having for a while, which this workaround prevented. But if we can't reproduce I'm gonna have a hard time convincing you to merge it :D |
No worries! Reopen if you hit the problem again. Thanks!! |
Hi @manelclos – would you consider re-opening/merging this PR? I still have the issue with the latest changes (master), and would love to get this merged because it would avoid having to maintain a fork just for this simple change Obviously there's probably more use cases out there than mine, so I would appreciate if this can be merged as soon as most general use cases are not impacted negatively – and just to be clear, I don't think they are I don't see any breaking side-effects to moving the code, and it seems to solve this issue. In summary, looks pretty safe to merge imho (I have been using this change in production since 2018 BTW) Let me know what you think |
Sure thing. Will test as per your instructions above. |
Codecov Report
@@ Coverage Diff @@
## master #274 +/- ##
=========================================
Coverage ? 80.42%
=========================================
Files ? 8
Lines ? 470
Branches ? 68
=========================================
Hits ? 378
Misses ? 60
Partials ? 32 Continue to review full report at Codecov.
|
Just tested this, I only get one request when changing Person and the Talents list is populated. |
Thanks for looking into it again. We have discussed this before, I couldn't get the repro to do the same as my personal project. That must be because of incompatibilities between different django admin extensions. I use django-nested-admin, which has to trigger the For some reason this extension has the whole formset created on the page, and duplicate them every time a user press on "add another". This procedure replaces all the This works fine for any formset created by django but not for those created by django-nested-inline. The main issue I can see is the onload method in django-smart-selects not filtering the elements with id including This PR was a workaround to avoid the multiple requests populating the list of available values more than once. I actually created another PR with the proper fix (exclude any elements where id includes Therefore I would suggest looking at #332 instead. It shouldn't break anything else (famous last words) |
For some reasons, when using
horizontal=True
, thechange
event is triggered twice, and so is the API request to retrieve the values.The result is that the
_from
SelectBox is filled with twice the same values.Moving the reset of the SelectBox cache from within the API request
.then()
method works around the issue.Not entirely sure if it needed to be outside for anything. Please test before merging