I want to use a jForms form in a Joomla modal window
I use:
- Joomla 3.4.5
- Bootstrap 3.3.5
- jQuery 1.11.3
- mootools (don't know which version)
I load the needed scripts via JHTML::_('behavior.modal');
,
add .modal
to the a
element and used the Joomla url snippet &tmpl=component
for only displaying the component.
The form is displayed in the modal.
Errors
Every time I open the modal, javascript gives me this error
Uncaught TypeError: jQuery(...).find(...).radioToBtn is not a function
The form is still displayed.
If i close it and open it again this error appears Uncaught TypeError: Cannot read property 'response' of null
Then, after some closing and opening, the form will be displayed double.
I kinda solved it.
1. The first step was to minimize the number of loaded scripts.
I unset mootools completly - because no body wants it. I noticed Joomla loaded the bootstrap.min.js, so it was loaded two times, one in my template and one from Joomla.
Now loading scripts:
Uncaught ReferenceError: JCaption is not defined
)2. The form component
jForms works with mootools, that's because I switched to Visforms - seems to work fine.
3. Implement the Bootstrap modal
In the
index.php
after the opening body, I created the "standard modal".Later the content will be loaded dynamicly into the modal.
3.1. The Modal trigger
To trigger the modal I have a button or a link.
It's connected to the "standard modal" but with the unique class
.callback-modal
. So later The script knows what kind of button this is.(Could have used an ID instead...)
3.2. The Javascript
The function:
Execute the function for our
.callback-modal
:Because of the
&tmpl=component
after the link, Joomla will only display the component itselfe.And because it's a function I can now create as many modals as I want. (It's not working perfectly with multiple modals)
Edit
I optimized the script for more dynamic modals.
Now you don't have to do this extra coding were you tell the script which class and what href the link has (Step 3.2).
In this case I switched from Bootstrap to Uikit, just because I do not understand Bootstraps remote method. I think with Bootstrap 4 the script can be adapted very easily.
Code
At the top of the index file sits again the basic modal:
The trigger links look like this:
Script:
On every link with the
.modal-trigger
class it adds the needed Uikit data attributesdata-uk-modal", "{target:'#modal'}
,grabs the link and loads it into the
.uk-modal-content
.All content will be removed after closing the modal.