Merge pull request #102 from roccivic/fix-form-onsubmit

Fixed bug #3583316 - Inline onsubmit not triggered
This commit is contained in:
Michal Čihař 2012-11-05 00:06:47 -08:00
commit 304d232fb9

View File

@ -119,7 +119,7 @@ var AJAX = {
*
* @return void
*/
requestHandler: function (e) {
requestHandler: function (event) {
// In some cases we don't want to handle the request here and either
// leave the browser deal with it natively (e.g: file download)
// or leave an existing ajax event handler present elsewhere deal with it
@ -134,19 +134,16 @@ var AJAX = {
return true;
}
e.preventDefault();
e.stopImmediatePropagation();
event.preventDefault();
event.stopImmediatePropagation();
if (AJAX.active == true) {
// Silently bail out, there is already a request in progress.
// TODO: save a reference to the request and cancel the old request
// when the user requests something else. Something like this is
// already implemented in the PMA_fastFilter object in navigation.js
return false;
} else {
AJAX.active = true;
}
this.$msgbox = PMA_ajaxShowMessage();
$('html, body').animate({scrollTop: 0}, 'fast');
var isLink = !! href || false;
@ -161,9 +158,23 @@ var AJAX = {
this._debug && console.log("Loading: " + url); // no need to translate
if (isLink) {
AJAX.active = true;
this.$msgbox = PMA_ajaxShowMessage();
$.get(url, params, AJAX.responseHandler);
} else {
$.post(url, params, AJAX.responseHandler);
/**
* Manually fire the onsubmit event for the form, if any.
* The event was saved in the jQuery data object by an onload
* handler defined below. Workaround for bug #3583316
*/
var onsubmit = $(this).data('onsubmit');
// Submit the request if there is no onsubmit handler
// or if it returns a value that evaluates to true
if (typeof onsubmit !== 'function' || onsubmit.apply(this, [event])) {
AJAX.active = true;
this.$msgbox = PMA_ajaxShowMessage();
$.post(url, params, AJAX.responseHandler);
}
}
},
/**
@ -377,6 +388,22 @@ var AJAX = {
}
};
/**
* Here we register a function that will remove the onsubmit event from all
* forms that will be handled by the generic page loader. We then save this
* event handler in the "jQuery data", so that we can fire it up later in
* AJAX.requestHandler().
*
* See bug #3583316
*/
AJAX.registerOnload('functions.js', function () {
// Registering the onload event for functions.js
// ensures that it will be fired for all pages
$('form').not('.ajax').not('.disableAjax').each(function () {
$(this).data('onsubmit', this.onsubmit).attr('onsubmit', '');
});
});
/**
* An implementation of a client-side page cache.
* This object also uses the cache to provide a simple microhistory,