guillaumepotier / Parsley.js

Validate your forms, frontend, without writing a single line of javascript
http://parsleyjs.org
MIT License
9.05k stars 1.32k forks source link

`whenValidate` not affecting UI #1349

Closed richard-jones closed 3 years ago

richard-jones commented 3 years ago

What kind of issue is this? (put 'x' between the square brackets)

I am making the following call

this.form.parsley().whenValidate().done(() => {
    this.jq("#cannot-submit-invalid-fields").hide();
}).fail(() => {
    this.jq("#cannot-submit-invalid-fields").show();
});

(where this.form is a reference to a jQuery element for the form).

On fail a message is shown to the user saying that they cannot submit. As I am using whenValidate, I am also expecting the UI to update to highlight the invalid field, and provide validation error messages.

What actually happens when I run this is that the message is shown to the user as expected, but the UI is not updated with the parsley errors.

On the parsley object, there is a property validationResult and it has the value false. I looked in the fields property of the parsley object, and I could not see any invalid fields:

>>> parsley.fields.filter(x => !x.validationResult)
Array []

(where parsley is the result of calling this.form.parsley() above, and then running whenValidate)

I wonder if this lack of invalid fields is the reason the UI has not been updated. What I can't work out is how I can get a validation failure, but have no invalid fields. I do have invalid fields, and I'm trying to get them to be highlighted.

richard-jones commented 3 years ago

My bad, this was a very oblique bug in a custom validator that was causing a reset on the parsley field under certain circumstances, and giving the impression that the UI was not updated. In fact the UI was updated and reset all so quickly that you couldn't tell. Sorry for the noise!