From 29d70fdf2369669aeae6f94e7dd3bc7f30eed5f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20Gutie=CC=81rrez=20Jime=CC=81nez-Pen=CC=83a?= Date: Mon, 12 Oct 2015 12:17:08 +0200 Subject: [PATCH 1/2] Prevent double submit and custom text on submit button. Function to prevent double submit. Put custom text on submit button when form is submitting (adding option: submitText). --- dist/verify.notify.js | 48 ++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/dist/verify.notify.js b/dist/verify.notify.js index 11ce621..de77da1 100644 --- a/dist/verify.notify.js +++ b/dist/verify.notify.js @@ -551,7 +551,7 @@ $.notify.addStyle("bootstrap", { window.console[fns[i]] = $.noop; if(!$) return; - + var I = function(i){ return i; }; function log() { @@ -610,7 +610,7 @@ $.notify.addStyle("bootstrap", { if($.console === undefined) $.console = console; - + $.consoleNoConflict = console; }(jQuery)); @@ -735,57 +735,57 @@ var Class = null; var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/; // The base Class implementation (does nothing) Class = function(){}; - + // Create a new Class that inherits from this class Class.extend = function(prop) { var _super = this.prototype; - + // Instantiate a base class (but only create the instance, // don't run the init constructor) initializing = true; var prototype = new this(); initializing = false; - + // Copy the properties over onto the new prototype for (var name in prop) { // Check if we're overwriting an existing function - prototype[name] = typeof prop[name] == "function" && + prototype[name] = typeof prop[name] == "function" && typeof _super[name] == "function" && fnTest.test(prop[name]) ? (function(name, fn){ return function() { var tmp = this._super; - + // Add a new ._super() method that is the same method // but on the super-class this._super = _super[name]; - + // The method only need to be bound temporarily, so we // remove it when we're done executing - var ret = fn.apply(this, arguments); + var ret = fn.apply(this, arguments); this._super = tmp; - + return ret; }; })(name, prop[name]) : prop[name]; } - + // The dummy class constructor function Class() { // All construction is actually done in the init method if ( !initializing && this.init ) this.init.apply(this, arguments); } - + // Populate our constructed prototype object Class.prototype = prototype; - + // Enforce the constructor to be what we expect Class.prototype.constructor = Class; // And make this class extendable Class.extend = arguments.callee; - + return Class; }; })(); @@ -1031,9 +1031,11 @@ var globalOptions = { if(!opts) opts = {color: 'red'}; $.notify(element, text, opts); } - } + }, + submitText: "Sending..." }; + //option object creator inheriting from globals function CustomOptions(opts) { $.extend(true, this, opts); @@ -1655,11 +1657,23 @@ var ValidationForm = null; this.submitResult === undefined) { this.submitPending = true; + this.validate(this.doSubmit); //have result } else if (this.submitResult !== undefined) { - submitForm = this.options.beforeSubmit.call(this.domElem, event, this.submitResult); + + if(this.submitResult == true) + { + //input submit + var idInputSubmit = this.domElem[0][1].id; + + // disable input submit for preventing double submit + $('#'+idInputSubmit).prop('disabled', true); + $('#'+idInputSubmit).val(globalOptions.submitText); + + submitForm = this.options.beforeSubmit.call(this.domElem, event, this.submitResult); + } } if(!submitForm) event.preventDefault(); @@ -2564,4 +2578,4 @@ log("plugin added."); }); })(jQuery); -}(window,document)); \ No newline at end of file +}(window,document)); From d0cc6940d39d13975e5fa2ce7fe9477162580c71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20Guti=C3=A9rrez=20Jim=C3=A9nez-Pe=C3=B1a?= Date: Thu, 15 Oct 2015 12:28:07 +0200 Subject: [PATCH 2/2] Update verify.notify.js --- dist/verify.notify.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dist/verify.notify.js b/dist/verify.notify.js index de77da1..2bc05d8 100644 --- a/dist/verify.notify.js +++ b/dist/verify.notify.js @@ -1666,7 +1666,9 @@ var ValidationForm = null; if(this.submitResult == true) { //input submit - var idInputSubmit = this.domElem[0][1].id; + var idForm = this.domElem[0]; + var inputSubmit = $(idForm).find(':submit'); + var idInputSubmit = $(inputSubmit).attr('id'); // disable input submit for preventing double submit $('#'+idInputSubmit).prop('disabled', true);