-
-
Notifications
You must be signed in to change notification settings - Fork 53
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
Correctly instantiate select2 on newly created django inlines #249
Comments
Hi @jurrian, Thank you for reaching out. Would you care to elaborate a bit more on some of my questions? I am looking forward to hearing back from you. Cheers! |
@codingjoe I think it has not worked for any Django version, judging on the other issues I mentioned which were opened in 2013. I guess not many ppl are Django-Select2 this way, I don't like the autocomplete fields that are using an endpoint cause it is an extra call, it also requires additional configuration. Since the html formfield_overrides = {ForeignKey: {'widget': Select2Widget}} That worked perfectly out of the box, except for those inlines for which this easy javascript fix works well. |
Hi @jurrian, True. We also didn't have official admin support since recently. Would you care to create a patch for this? Preferably in a separate JS file, to keep the frontend payload and complicity small. Thanks! |
@codingjoe, I can make a PR for this. I can put it in a separate JS file, but I don't see a way to detect if it will be on an admin page or not. So either:
Another thought: would adding 20 lines / 940 chars of code to the existing JS file be observable at all in terms of page load? |
@jurrian there is a fairly newly added admin mixin. The file should only be port of the |
I would be fine with making a PR for the code that I provided in one single file. But to be honest, I am not willing to invest much more time in adding it to a mixin and testing that. If someone wants to spend time in that, more than welcome. Otherwise the problem is known and fix can be found here for purpose of reference. |
As described in #249 and #297 django-select2 does not currently work with selects added dynamically in the Django admin. The solution was implemented in #249 and all credit should go to Jurrian Tromp. I only added a small correction: ```diff - jqRow.find('.select2-container').remove() + jqRow.find('.django-select2').parent().find('.select2-container').remove() ``` to only remove `.select2-container` when it is a sibling of `.django-select2`. Otherwise the wrong `.select2-container` might get deleted. --------- Co-authored-by: Johannes Maron <[email protected]>
Describe the bug
When a new inline is added using the "Add another ..." button, the Select2 elements on that inline are not working.
Something similar has been proposed in an old PR, I've adapted it to the new situation.
If it's appreciated I can create a PR with the change I made.
Other possible related issues: applegrew#65, applegrew#32
Exception & Traceback
Clicking will provide no logs or trace.
Code Snippet
I've added this code to the django_select2/django_select2.js file in order to fix it:
To Reproduce
Expected behavior
Normally the dropdown with options appears.
Screenshots
Clicking on the select will do nothing.
The text was updated successfully, but these errors were encountered: