Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,24 @@ $.extend($.fn, {

if ( validator.settings.onsubmit ) {

this.validateDelegate( ":submit", "click", function( event ) {
this.validateDelegate( ":submit, :submit *", "click", function( event ) {
if ( validator.settings.submitHandler ) {
validator.submitButton = event.target;
}

// locate the actual "action" element
var actionTarget = $(event.target);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couldn't we just check wheter event.target is of type input, and if not, find for the input starting from event.target?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is exactly what the code does. With the extension in must not limit the test to input only and needs to work for <button type=”submit”> also. Basically exactly what :submit selector test does. This solution (=use the :submit selector) seems cleaner and more readable to me. Moreover at this point there is no need to worry about the performance.
As for the performance I did not measure the impact of the validateDelegate compound selector, that one I would suspect first.
Just my opinion, if I’m missing anything, please, let me know.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but I want to achieve it in a different way as implemented currently. Instead of binding to :submit * we should do a find only when event.target doesnt work (means it is not a input).

This would help because only chrome needs to pay for this edge case, not all browsers

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm after re-reading it looks like everything is in place.

Please just add the unit test

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, understand, that makes sense but it implies the other solution described in the issue-1370 … getting rid of the validateDelegate, which now filters out the click events coming from the inner elements. That solution would be more efficient however (and a bigger change in the current code)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, soory, I have missed your previous reply ... ignore the post above ....

if ( !actionTarget.is( ":submit" ) ) {
actionTarget = actionTarget.closest(":submit");
}

// allow suppressing validation by adding a cancel class to the submit button
if ( $( event.target ).hasClass( "cancel" ) ) {
if ( actionTarget.hasClass( "cancel" ) ) {
validator.cancelSubmit = true;
}

// allow suppressing validation by adding the html5 formnovalidate attribute to the submit button
if ( $( event.target ).attr( "formnovalidate" ) !== undefined ) {
if ( actionTarget.attr( "formnovalidate" ) !== undefined ) {
validator.cancelSubmit = true;
}
});
Expand Down