how to auto close modal window on form submit?

4,215 views
Skip to first unread message

Nick Weavers

unread,
Jun 21, 2011, 8:52:29 AM6/21/11
to Joomla! General Development
I have a form that pops up in a modal window in an iframe and when the
form is submitted the modal window doesn't close automatically, which
is what I need. I looked at Andrew Eddie's example (http://
www.theartofjoomla.com/home/6-layouts/16-layout-overrides-popup-login-box.html)
for doing the login form as a modal popup and noticed his example
doesn't set a value of {handler: 'iframe', ... in the link's rel attr,
but instead sets a value of {ajaxOptions: {method: "get"}, ...

So I tried this:

<a class="modal"
href="index.php?
option=com_mycomp&task=training.takeCourseEnquiry&course_id=<?php echo
$row->course_id; ?>&id=0&tmpl=component"
rel="{ajaxOptions: {method: 'get'}, size: {x: 640, y: 480}}">
Enquiry
</a>

When I try this I get the following error reported in Firebug:

uncaught exception: [Exception... "Could not convert JavaScript
argument arg 0 [nsIDOM3Node.compareDocumentPosition]" nsresult:
"0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)" location: "JS frame ::
http://mydomain/cms/media/system/js/mootools-core.js :: <TOP_LEVEL> ::
line 1" data: no]
http://www.lexius.co.uk/cms/media/system/js/mootools-core.js
Line 1

I googled for "mootools modal" and found links for plugins, but wasn't
sure what Joomla comes with.
Can anyone help?

TIA,
Nick

Nicholas K. Dionysopoulos

unread,
Jun 21, 2011, 10:48:17 AM6/21/11
to joomla-de...@googlegroups.com
You can set the handler as iframe normally. The trick is what happens after you submit the form. After the data is processed and stored in the database (or you are done doing whatever you have to do with it), your controller should redirect to a different layout of the form. That layout should contain this simple Javascript code:

<script type="text/javascript">
window.setTimeout('closeme();', 300);
function closeme()
{
parent.SqueezeBox.close();
}
</script>

This will ask the parent window (the iframe's parent is your main page) to close the SqueezeBox (which is where your iframe is in), therefore closing the modal dialog.

Note: this code has been tested with Joomla! 1.5. I am not sure if it works on Joomla! 1.6, but you can check it out nonetheless and tell us how it goes.

Cheers,

-- 
Nicholas K. Dionysopoulos
Lead Developer, AkeebaBackup.com
--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To post to this group, send an email to joomla-de...@googlegroups.com.
To unsubscribe from this group, send email to joomla-dev-gene...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/joomla-dev-general?hl=en-GB.

Nick Weavers

unread,
Jun 21, 2011, 1:21:16 PM6/21/11
to Joomla! General Development
Thanks Nicholas,

Nice trick. It works fine in 1.6.

Nick

Nicholas K. Dionysopoulos

unread,
Jun 21, 2011, 1:22:22 PM6/21/11
to joomla-de...@googlegroups.com
You're welcome :)

-- 
Nicholas K. Dionysopoulos
Lead Developer, AkeebaBackup.com

Andy Nagai

unread,
Jul 1, 2011, 11:43:56 PM7/1/11
to joomla-de...@googlegroups.com
I dont use handler option either. It will just make an ajax call and
dump whatever your calling right into the DOM. You just call some view
with format=raw and dumps it into the dom. When the form submits it
makes a ajax call to save the data and on successful return I execute
that close statement.

Saves some microseconds opening up an iframe.

Andy Nagai

unread,
Jul 1, 2011, 11:51:51 PM7/1/11
to joomla-de...@googlegroups.com
no thats wrong. It does put it in a iframe. Just my imagination.
Reply all
Reply to author
Forward
0 new messages