Skip to content

Commit

Permalink
Core: Don't call submitHandler when in debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Arkni committed Jul 29, 2018
1 parent e26547a commit b115011
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 18 deletions.
3 changes: 2 additions & 1 deletion src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ $.extend( $.fn, {
// Prevent form submit to be able to see console output
event.preventDefault();
}

function handle() {
var hidden, result;

Expand All @@ -64,7 +65,7 @@ $.extend( $.fn, {
.appendTo( validator.currentForm );
}

if ( validator.settings.submitHandler ) {
if ( validator.settings.submitHandler && !validator.settings.debug ) {
result = validator.settings.submitHandler.call( validator, validator.currentForm, event );
if ( hidden ) {

Expand Down
6 changes: 0 additions & 6 deletions test/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
21 changes: 10 additions & 11 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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" );
Expand All @@ -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
Expand Down Expand Up @@ -1370,13 +1367,16 @@ 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 ) {
assert.equal( response, "Hi Peter, welcome back." );
done();
}
} );

return false;
}
} );
jQuery( "#signupForm" ).triggerHandler( "submit" );
Expand Down Expand Up @@ -2424,7 +2424,6 @@ QUnit.test( "calling blur on ignored element", function( assert ) {

form.validate( {
ignore: ".ignore",
submitHandler: $.noop,
invalidHandler: function() {
$( "#ss1" ).blur();
}
Expand Down

0 comments on commit b115011

Please sign in to comment.