From d38c99739fc4db521d75654ac7847e313506a8ac Mon Sep 17 00:00:00 2001 From: Brahim Arkni Date: Sun, 29 Jul 2018 01:31:31 +0100 Subject: [PATCH] Core: Don't call submitHandler when in debug mode Fixes #2042 --- src/core.js | 4 +++- test/methods.js | 6 ------ test/test.js | 21 ++++++++++----------- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/core.js b/src/core.js index b32519893..04f98bf91 100644 --- a/src/core.js +++ b/src/core.js @@ -49,6 +49,7 @@ $.extend( $.fn, { // Prevent form submit to be able to see console output event.preventDefault(); } + function handle() { var hidden, result; @@ -64,7 +65,8 @@ $.extend( $.fn, { .appendTo( validator.currentForm ); } - if ( validator.settings.submitHandler ) { + // Only call the submit handler in case the validator is not on debug mode + if ( validator.settings.submitHandler && !validator.settings.debug ) { result = validator.settings.submitHandler.call( validator, validator.currentForm, event ); if ( hidden ) { diff --git a/test/methods.js b/test/methods.js index 43f2ec0c1..db2d67169 100644 --- a/test/methods.js +++ b/test/methods.js @@ -500,9 +500,6 @@ QUnit.test( "remote", function( assert ) { required: "Please", remote: jQuery.validator.format( "{0} in use" ) } - }, - submitHandler: function() { - assert.ok( false, "submitHandler may never be called when validating only elements" ); } } ), done = assert.async(); @@ -595,9 +592,6 @@ QUnit.test( "remote extensions", function( assert ) { username: { required: "Please" } - }, - submitHandler: function() { - assert.ok( false, "submitHandler may never be called when validating only elements" ); } } ), done = assert.async(); diff --git a/test/test.js b/test/test.js index dbe901556..870d625d5 100644 --- a/test/test.js +++ b/test/test.js @@ -167,14 +167,10 @@ QUnit.test( "valid() ???", function( assert ) { v.errorList = errorList; assert.ok( !v.valid(), "One error, must be invalid" ); v.destroy(); - v = $( "#testForm3" ).validate( { - submitHandler: function() { - assert.ok( false, "Submit handler was called" ); - } - } ); - assert.ok( v.valid(), "No errors, must be valid and returning true, even with the submit handler" ); + v = $( "#testForm3" ).validate(); + assert.ok( v.valid(), "No errors, must be valid and returning true" ); v.errorList = errorList; - assert.ok( !v.valid(), "One error, must be invalid, no call to submit handler" ); + assert.ok( !v.valid(), "One error, must be invalid" ); } ); QUnit.test( "valid(), ignores ignored elements", function( assert ) { @@ -576,13 +572,14 @@ QUnit.test( "submitHandler keeps submitting button", function( assert ) { var button, event; $( "#userForm" ).validate( { - debug: true, + debug: false, submitHandler: function( form ) { - // Dunno how to test this better; this tests the implementation that uses a hidden input var hidden = $( form ).find( "input:hidden" )[ 0 ]; assert.deepEqual( hidden.value, button.value ); assert.deepEqual( hidden.name, button.name ); + + return false; } } ); $( "#username" ).val( "bla" ); @@ -596,7 +593,7 @@ QUnit.test( "submitHandler keeps submitting button", function( assert ) { QUnit.test( "submitHandler keeps submitting button, even if descendants are clicked", function( assert ) { var button = $( "#testForm27 :submit" )[ 0 ]; var v = $( "#testForm27" ).validate( { - debug: true, + debug: false, submitHandler: function( form ) { // Compare the button with the `submitButton` property @@ -1370,6 +1367,7 @@ QUnit.test( "ajaxSubmit", function( assert ) { $( "#user" ).val( "Peter" ); $( "#password" ).val( "foobar" ); jQuery( "#signupForm" ).validate( { + debug: false, submitHandler: function( form ) { jQuery( form ).ajaxSubmit( { success: function( response ) { @@ -1377,6 +1375,8 @@ QUnit.test( "ajaxSubmit", function( assert ) { done(); } } ); + + return false; } } ); jQuery( "#signupForm" ).triggerHandler( "submit" ); @@ -2424,7 +2424,6 @@ QUnit.test( "calling blur on ignored element", function( assert ) { form.validate( { ignore: ".ignore", - submitHandler: $.noop, invalidHandler: function() { $( "#ss1" ).blur(); }