Giter Club home page Giter Club logo

Comments (11)

Rodeoclash avatar Rodeoclash commented on May 19, 2024

I'm also getting issues surrounding remote validation. I'm using the latest v1.7 version directly out of github, confirmed that I'm returning the correct "false" response.

Fields using remote validation get marked "valid" when submitting but block the form from being submitted. No error messages are displayed.

from jquery-validation.

ArthurClemens avatar ArthurClemens commented on May 19, 2024

When getting a succesful remote result after the field itself has no focus anymore, the invalid hash is not updated, only the successList. This results in a wrong count returned by numberOfInvalids().

from jquery-validation.

cvwillegen avatar cvwillegen commented on May 19, 2024

Ok, I've tracked it down a bit further. I've used 1.8 for this...

On line 950, in the 'success' function, validator.prepareElement(element) is called, which calls this.reset(), which assigns this.errorList = [];. This resets the size() of the validator, so that the form validates to true always.

On line, 958, also in the 'success' function, but when the remote check returns 'false', validator.showErrors(errors) is called with one error, namely the one returned from the remote. In this function, on line 357, there is the assignment this.errorList = [];. This resets the size() of the validator, so that the form has only one error, the one returned from the remote call.

So, in both cases, the error list is not what it should be after a remote validation.

Note that I am running a $('form').valid() from a button, I'm not 'submitting' the form per se.

AFAICS, this has (unfortunately) nothing to do with the field having focus or not.

from jquery-validation.

mlynch avatar mlynch commented on May 19, 2024

Similar to #286

from jquery-validation.

mlynch avatar mlynch commented on May 19, 2024

@cvwillegen @Rodeoclash @ArthurClemens can one of you provide a failing test case on jsfiddle or something that shows this issue, using the new version of validate in git? Thanks.

from jquery-validation.

cvwillegen avatar cvwillegen commented on May 19, 2024

Max,

On Sat, May 5, 2012 at 7:44 PM, Max Lynch
[email protected]
wrote:

@cvwillegen @Rodeoclash @ArthurClemens can one of you provide a failing test case on jsfiddle or something that shows this issue, using the new version of validate in git? Thanks.

I haven't been able to break it, yet, and I now use the 'stock'
jquery.validate.js from GitHub. We do use remote validation quite a
lot, and so far, no problems with remote (nor with local) validation.

Christ van Willegen

09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0

from jquery-validation.

jasonday avatar jasonday commented on May 19, 2024

I'm having a similar issue with remote - in my case, the remote will return correctly on an invalid element the first time. However, if the field has success, and I put in an invalid value - it never triggers the remote call again.

http://stackoverflow.com/questions/11479383/jquery-validation-remote-method-only-triggering-once-wont-trigger-after-vali

from jquery-validation.

X-Coder avatar X-Coder commented on May 19, 2024

The same issue here too. I changed my code a bit so the remote is only called on blur and not on keydown and validation is done only on blur.

Steps to reproduce (on latest 1.9.0):

  1. enter invalid data into a "remote" input field
  2. tab to next input field, so the invalid one looses focus / calling blur event. The input field should now getting a errorClass and the invalid label.
  3. goto previous input field and correct the invalid data
  4. tab again to next field, now the invalid label disappears because the data is valid, but the input field still has the errorClass instead of validClass.

I traced it down too to the thing cvwillegen reported a year ago:
validator.prepareElement(element) is called right after the success method of remote function, which calls reset(), and reset clears (amongst other things) currentElements[], but a a filled currentElements is required right before the call to validator.showErrors() in the success method. currentElements is required by validElements() used in defaultShowErrors() (line 614) to clear errorClass and set validClass (line 615).

Suggested fix:
After disabling the call to validator.prepareElement(element) in remote() success method to prevent reset() being called, it seems to fix my issue. Is this call required for something? Running the testcase afterwards didn't trigger any errors.

The code I used looks similar to this:
$('form').validate({
rules: {
username: {
required: true,
remote: {url: "index.php?action=isUsernameFree", async: false}
}
}
});

// this is for triggering the remote request only on blur by disabling onkeyup temporarily:
$('#username').on({
blur: function () {
$(this).closest('form').validate().settings.onkeyup = $.validator.defaults.onkeyup;
},
focus: function () {
$(this).closest('form').validate().settings.onkeyup = false;
}
});

from jquery-validation.

clepore avatar clepore commented on May 19, 2024

I had the same exact issue and I commented that same line out and everything is good now. Thanks!

from jquery-validation.

mlegenhausen avatar mlegenhausen commented on May 19, 2024

I have also this issue when using the form() method. I had disabled all on-Events and then it seems obviously that a sync call like form() can never handle an async event like a remote validation.

from jquery-validation.

jzaefferer avatar jzaefferer commented on May 19, 2024

I stil can't reproduce this issue. @X-Coder provided the most detailed steps to reproduce, but he uses async: false, which isn't supported and never will be.

I'm happy to look at reproducible issues, so if anyone else is (still) having this issue, please create a new ticket with a testpage and steps to reproduce.

from jquery-validation.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.