-
Notifications
You must be signed in to change notification settings - Fork 143
Initialization of the external JS #158
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
Comments
btw, I got it works using: monim67/django-bootstrap-datepicker-plus#47 (comment) |
@rez0n The form in the modal is loaded from form-url and as such the form on that url should already have fields instantiated with desired js. Any js that is needed for the form itself should be included in the template for the form. See script tag below. Once the form is loaded in the modal it can't use the js loaded in the base html page. See also comments in #25 and #34. The solution you got more or less describes practically the same thing, to load the js used in the form before it's rendered in the modal. To say it once more but differently, the form defined on your form-url should already be fully functional on that form-url, which you can visit and check, and the package will then just take that form and load it into the opened modal.
|
@trco thank your for the answer, I saw #25 yesterday and it was help me to call select2 again after modal was opened, but I need to add timeout ot get it works. This is obv not good solution because I still have initial errors in the console on modal open.
Describing workflow. If you have a time and want to understand issue you can take a look at the simple demo app: https://github.com/rez0n/django-select2-bootstrap-modal
The demo app contains Category and Post objects. The database contains a single post and few categories. In general, I not sure it is django-bootstrap-modal-forms issue at all but it affects any included JS added to the modal content and if you can fix this it will be helpful for new users. |
@rez0n I was considering to improve package and add option to pass external JS to modalForm when instantiating it. I researched your case with the great example repo you shared. I found out that Based on django_select2 code:
I didn't research the first option, but I checked the second one. I copied select2.min.js from CDN to your app/static folder and set I added select2.min.js directly to the Media class of your form and voila. The error was gone and form field was instantiated as select2 field. See the PR I opened on your repo. The conclusion is that modalForm doesn't need functionality you're describing, since Django allows to pass assets such as external JS to the forms via Media class. See docs for the examples https://docs.djangoproject.com/en/4.2/topics/forms/media/#assets-as-a-static-definition. This doc says that everything you can use same Media class on Form as on Widgets, which are described. I won't explore what's the reason behind My action item is to add the info around passing assets to the forms through the Media class on the forms to the docs of my package. The code... forms.py NOTE: select2.min.js should be present in static files.
modal template NOTE: {{ form.media }} should be present at the top.
|
Uh oh!
There was an error while loading. Please reload this page.
Hi, using django-bootstrap-modal-forms I faced the issue to unable correctly include external JS libraries in the modal form.
On the first modal open, I have errors in JS console, but on second modal open it works correctly.
I already had a discussion in the django-select2 repository: codingjoe/django-select2#47 (you can take a look at logs and also I posted a demo app)
But now I faced with the same issue on including django-bootstrap-datepicker-plus

Looks like jquery runs before the modal DOM is ready.
Are you can advise some ideas on how to overcome that?
Probably related to #142 and #141
Form code, not sure it is helpful, because too common, but anyway.
The text was updated successfully, but these errors were encountered: