Skip to content

Commit 16227e4

Browse files
Arknistaabm
authored andcommitted
Tests: Pass on the value of the used submit button for scripted submits
The only scripted submits in this plugin are triggered by `stopRequest()` when the remote method finished validating an element and the form was submitted
1 parent e0876fb commit 16227e4

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

test/test.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,56 @@ QUnit.test( "submitHandler keeps submitting button, even if descendants are clic
450450
$( button ).find( "span" ).click();
451451
} );
452452

453+
QUnit.test( "handle() should ensure the value of the used submit button is passed on for scripted submit triggered by stopRequest()", function( assert ) {
454+
var $form = $( "#userForm" );
455+
var button = $( ":submit", $form )[ 0 ];
456+
var done = assert.async();
457+
var v = $form.validate( {
458+
debug: true,
459+
rules: {
460+
username: {
461+
remote: {
462+
url: "issue1508.php"
463+
}
464+
}
465+
}
466+
} );
467+
var i = 1;
468+
469+
// Register a `submit` event after the one registred by this plugin
470+
$form.on( "submit", function() {
471+
472+
// Ignoring the first submit that was triggered manually by clicking
473+
// the submit button. The first submit will be aborted by this plugin
474+
// in order to wait for `remote` method to finish validating the input
475+
if ( i > 0 ) {
476+
i--;
477+
return false;
478+
}
479+
480+
// The second submit is the one triggered by `stopRequest()` after the
481+
// `remote` method has finished processing its attached input.
482+
483+
// Compare the button with the `submitButton` property
484+
assert.deepEqual(
485+
v.submitButton, button, "The submitButton property should be the same as button"
486+
);
487+
488+
var hidden = $form.find( "input:hidden" )[ 0 ];
489+
assert.deepEqual( hidden.value, button.value );
490+
assert.deepEqual( hidden.name, button.name );
491+
492+
done();
493+
494+
return false;
495+
} );
496+
497+
$( "input[name='username']", $form ).val( "something" );
498+
499+
// Submit the form
500+
$( button ).click();
501+
} );
502+
453503
QUnit.test( "validation triggered on radio/checkbox when using keyboard", function( assert ) {
454504
assert.expect( 1 );
455505
var input, i, events, triggeredEvents = 0,

0 commit comments

Comments
 (0)