Skip to content

Instantly share code, notes, and snippets.

@dongilbert
Created April 27, 2012 16:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dongilbert/2510783 to your computer and use it in GitHub Desktop.
Save dongilbert/2510783 to your computer and use it in GitHub Desktop.
Joomla Request Confirmation Before Closing
/*
* This goes at the top of your plugin edit view,
* and will ask for confirmation before you leave.
* Be sure to replace viewname with your controller
* name, shortened. If you follow 2.5 guidelines
* with sub controllers that handel specific parts
* of the application, then this will work fine.
*/
Joomla.submitbutton = function(task) {
var confirmation = true;
var viewname = <?php echo JRequest::get('view'); ?>;
if(task === viewname + '.cancel')
{
var confirmation = confirm('Have changes to save? Click Cancel, and then Save. Otherwise, click ok.');
}
if(confirmation)
{
if (task == viewname + '.cancel' || document.formvalidator.isValid(document.id(viewname + '-form'))) {
Joomla.submitform(task, document.getElementById(viewname + '-form'));
}
else {
alert('<?php echo $this->escape(JText::_('JGLOBAL_VALIDATION_FORM_FAILED'));?>');
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment