Skip to content

fix for issue #430 #436

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from

Conversation

WickyNilliams
Copy link
Contributor

Firstly, apologies if I've done something wrong here, my first effort at contributing a fix. I think I've committed against an issue, though I may have done it completely wrong!

This covers the case where the the form has failed server-side validation and so the form is sent back to the user with server-generated error labels. Currently the validation plugin will not update these labels if new user input causes client-side validation to fail. This commit fixes that.

I made the assumption that any existing label which already has the errorClass assigned is safe to update with a new message, which i believe is a safe assumption (why would any label other than a validation error label, already have the errorClass assigned?)

Thanks,
Nick

made assumption that any existing label which already has errorClass is
safe to update with a new message.
@@ -683,7 +683,7 @@ $.extend($.validator, {
label.removeClass( this.settings.validClass ).addClass( this.settings.errorClass );

// check if we have a generated label, replace the message then
if ( label.attr("generated") ) {
if ( label.attr("generated") || label.hasClass(this.settings.errorClass) ) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Line 683 adds the errorClass to the label, so this would always be true. Could you address that, along with unit tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

D'oh, can't believe i missed that! Hmm, I suppose we could check whether it's valid to replace the message before the error class is added. e.g.

var okToReplace = label.attr("generated") || label.hasClass(this.settings.errorClass);

label.removeClass( this.settings.validClass ).addClass( this.settings.errorClass );

if(okToReplace) {
    // do replacement
}

Does that seem fair to you?

Copy link
Collaborator

Choose a reason for hiding this comment

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

That should work. Unit tests to the rescue!

Feel free to update this PR. Can just amend the existing commit and force-push. Or add new commits and I'll squash later.

@jzaefferer
Copy link
Collaborator

Thanks for the contribution. Added an inline comment above.

@WickyNilliams
Copy link
Contributor Author

Would you like any further changes in a fresh branch or are you ok to accept on master?

@jzaefferer
Copy link
Collaborator

Generally PRs should come from branches, that way to can start working on something else. If you don't plan to do that anyway, just push commits to master and I'll merge from there.

@WickyNilliams
Copy link
Contributor Author

Finally got around to fixing previous commit and adding a unit test - completely forgot about this!

This is the first time I've ever had to sync a seriously out of date fork, so apologies if anything is out of place. Happy to make any adjustments you require :)

@WickyNilliams
Copy link
Contributor Author

ahem :)

@jzaefferer
Copy link
Collaborator

Finally merged this. I looked at errorsFor, which calls errors, which filters by errorClass. So errorsFor only returns labels that already have the errorClass, making the check unncessary. I've updated your patch accordingly and squashed it into a single commit.

Thanks for the contribution!

@WickyNilliams
Copy link
Contributor Author

Thanks for that :) Sorry for the ignorance, not familiar with the codebase to understand what you wrote above! Does this mean my change wasn't necessary or that there was a better place to put the fix? My unit test still helped I hope!

@jzaefferer
Copy link
Collaborator

You can compare my commit above to your original changes. The fix was valid, it just was more complicated than necessary.

@WickyNilliams
Copy link
Contributor Author

Makes sense, this is why domain knowledge is valuable :) Thanks for accepting!

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