ParsleyJS - reset field on "backspace" (when deleting input)

315 views Asked by At

I was wondering how to reset() a ParsleyJS field if a user is deleting his input.

When I enter some input in the "First Name" field it validates successfully on input. Good.

If I now figure out that I made a typo while filling out that field, and I hit the backspace button on my keyboard until it is empty, it invalidates with parsley-error. However, the other empty fields which I didn't fill out yet, e.g. "Last Name", are neither valid nor invalid.

So the form now shows a red/parsley-error but empty "First Name" field and a white and empty "Last Name" field, whereas both fields should look the same: white (not yet validated) and empty.

Thereofor, I think it would be logical that a field would, once emptied, be handled like a field that has never been filled. So neither parsley-success nor parsley-error should fire, or respectively, it should reset(). How can I achieve this?

I appreciate any input from your end!

Thanks

1

There are 1 answers

0
Marc-André Lafortune On

I don't know of a simple way to achieve what you want and can only discourage you from going against Parsley.

It is Parsley's contention that once you've tried to validate an invalid entry (for required fields that means clicking on 'Submit'), that you should be mostly done entering all the info. At that point, you probably want to click on 'Submit' again, and Parsley will show you all the errors that prevent you from doing that, no need to click 'Submit' over and over again.

I fail to see why a user would want to empty out a field at that point, and if she did why she'd want to keep it empty for more than half a second, or why she'd be confused by the fact that there's an error doing so.

Good luck