From aa94d647054e35b28b16bc2802965b9edd925ea2 Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Mon, 5 Nov 2012 00:14:11 +0000 Subject: [PATCH] Fixed bug #3583316 - Inline onsubmit not triggered --- js/ajax.js | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/js/ajax.js b/js/ajax.js index 3a4c1efdf8..13c1e4e9c9 100644 --- a/js/ajax.js +++ b/js/ajax.js @@ -142,11 +142,8 @@ var AJAX = { // 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, [e])) { + 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,