-
-
Notifications
You must be signed in to change notification settings - Fork 81
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
Select2 not working in inline #134
Comments
also paging @kptac , you seem to have edited the inline-template because something else did not work in #inline -- maybe you have some advice on how I could proceed to solve this problem? If not, that's completely fine, too. |
I haven't tested this with your code, but from the console error, you need to serve select2 js from your server instead of cdn as that error seems to be reporting that select2.min.js was blocked because of CORs policy. Also, confirm the jquery version that is required for django-select2. I have not used that before, so not really sure. I think that should resolve it for you (hopefully) |
thank you for your answer! I've since found that the CORs policy errors can be resolved by setting the following variables in your project- SELECT2_JS = 'select2/js/select2.min.js'
SELECT2_CSS = 'select2/css/select2.min.css'
SELECT2_I18N_PATH = 'select2/js/i18n' I've updated my error-example-repository accordingly. Unfortunately, this does not resolve the original problem and the select2- |
It turns out that this is a long-known problem: with an easy quick fix: (remove the For my particular case, adding this line to the $(".modal").removeAttr("tabindex"); I'm leaving this issue open nevertheless, until the solution is implemented. Tell me if I should make a pull-request, but it seems like an easy fix. There's probably a better solution, too. I've read that removing |
Good find. For the time being, in my opinion, I wouldn't use a modal or the default forms, but a custom form and not load all the entries directly on to the page. Instead, you can easily create an ajax request view, that will return a json response with the entries while users are typing / searching in the select2 js widget. You can read up on that here: https://select2.org/data-sources/ajax I have used that in one of my projects before, I can share some of the code for you if you need any assistance with it. Good luck. |
Indeed, I'm already using a custom form with an Ajax request to let users search through the entries :) (see my declarations above in the I just wanted to additionally demonstrate that when one uses the default form, the selects are not converted to select2. cheers |
I'm using inline CRUD-Views to add more complex information to objects. My setup is similar to the one described #133. I've noticed that custom select2-widgets are not working properly in modals. It's alright to just use the normal selects in some cases, however, for one particular inline-object, I need something to search through 350,000 entries. Unfortunately, when adding a select2-widget to a custom form, the widget does not work: one cannot enter anything and no request is sent to the "select2/"-urls. I've looked at the source code but I can't seem to find any clue on how to proceed. Help would much appreciated.
paging @luisza because they seem to have developed the
Inline
-logic.Here's a repository that has the complete example showing what doesn't work: https://github.com/benmaier/example-django-crud-admin-lte-select2
Here's the definitions of models, forms, and views.
models.py
forms.py
views.py
Now, when I navigate to http://localhost:8000/crud/institution/1/update , I see the right form:
However, when I want to choose a city, I cannot type anything:
Also, I'm getting these errors in the JavaScript-console:
Non-custom form
I can disable the custom form:
But then, the forms takes ages to load (in this example, it's loading 35,000 items into the select) and also the HTML-selects do not seem to be converted to select2-objects.
Related issues
I've seen that a number of people have problems with select2 and modals, so I'm linking a few threads I've found:
django-select2
doesn't work on inline forms darklow/django-suit#337The text was updated successfully, but these errors were encountered: