Skip to content

Conversation

javcz
Copy link

@javcz javcz commented May 27, 2015

A common scenario x will not work as expected, validation does not get cancelled. Proposed fix searches for the appropriate target when the inner element is clicked

javcz added 2 commits May 27, 2015 19:05
…r elements

A common scenario <button type="submit" class="cancel"><span class="maybesymbolfont">x</span><button> will not work as expected, validation does not get cancelled. Proposed fix searches for the appropriate target when the inner element is clicked
@javcz
Copy link
Author

javcz commented May 27, 2015

Oops, forgot to add in the original comment. I only was able to reproduce this behavior in the Chrome browser. Only Chrome has in the event.target property set to the inner button element when listened for the click on form. Other tested browsers (Firefox, IE11) have the event.target set to the button itself and the problem does not show there.

sorry, editing over the gighub web interface only
@javcz
Copy link
Author

javcz commented May 27, 2015

jsbin demonstrating the bug: http://output.jsbin.com/pagutolovo/10

The second button should not trigger the validation, however if you click the blue text on the button (make sure you hit the glyphs, not the button face), the validation will run. Chrome only (from what I have tested)

@javcz
Copy link
Author

javcz commented May 27, 2015

Sorry guys, I found too late this is a duplicate to #1370, just a slightly different solution of the problem

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 ....

@staabm
Copy link
Member

staabm commented Jun 2, 2015

I like this PR more then the alternative solution in issue-1370 because it is less obtrusive.

please integrate the unit test of https://github.com/jzaefferer/jquery-validation/pull/1392/files to make sure you are actually fixing the issue and we wont regress.

@javcz
Copy link
Author

javcz commented Jun 2, 2015

Hmm, sorry, I’m lost now. The PR-1392 seems to me to primary focus a quite different topic (clean removing of the validator from DOM) and it “by the way” replaces the validateDelegate by on event binding, which I believe solves the Webkit problem in a natural way (as the click event will bubble form the inner element and the handler will be invoked when reaching the parent :submit level – something what will not happen in the current implementation).
Just this solution is a bigger change to the current code and I understood that is the reason why you prefer to keep the validateDelegate. Once you plan to pull PR-1392 the change I have proposed is not needed anymore. Where exactly would you like me to add the unit test method?
I’m a total newbie in contributing to open projects, sorry for silly questions …

@staabm
Copy link
Member

staabm commented Jun 3, 2015

Lets hold on a bit and see what jzaeffer responds in the alternative PR. Thanks for your contribution until now.

@jzaefferer
Copy link
Collaborator

Due to recent changes, switching from custom delegation to using .on, this became much easier to fix.

@javcz javcz deleted the patch-1 branch June 30, 2015 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants