Vee-validate: Dirty and setPristine()

Created on 20 Oct 2016  路  15Comments  路  Source: logaretm/vee-validate

Hello,

In AngularJS and vue-validate, we have available the event "dirty". With the event, for example, we can see if the form was "manipulated" and added the validation check of the rules, enable - or not - the button to save the form data.

How to do this validation with vee-validate?

Thanks for the feedback.

Most helpful comment

I added:

  • reset: resets the flags for the specified field, if no arguments were provided it will reset all fields' flags.
  • setValid: sets the valid flag for a specified field and updates its computed flags (failed, and passed).
  • setDirty: sets the dirty flag for a specified and updates its computed flags (failed, passed, and clean).
  • dirty: gets the dirty flag for the specified field, if no arguments were provided it checks if at least one field is dirty.
  • clean: same as dirty, if no arguments were provided it checks if all fields are clean.
  • valid: same as dirty. if no arguemts were provided it checks if all fields are valid.
  • passed: same as dirty. if no arguments were provided it will check if all fields have passed.
  • failed: same as dirty. if no arguments were provided it will check if at least one field has failed.

@BrandonSurowiec @xereda I'm open to suggests for other methods you guys might find useful. But I'm closing this since I implemented some already.

All 15 comments

The "dirty" was implemented in the last release, but it works only by individual field.

https://github.com/logaretm/vee-validate/releases/tag/2.0.0-beta.13

We need a "dirty" that considers all the form fields that are being controlled by the vee-validate.

I'm considering adding helper methods to the fields object, like a method that tells you if any of the attached fields are dirty or not, same goes for other flags.

also the API would probably change to use methods instead since the proxy class can't be polyfilled properly mentioned here #42

I'm thinking about something like this:

fields.dirty(); // is at least one field dirty?
fields.dirty('email'); // is the email field dirty?

same goes for other properties.

also I would add some way to reset those flags like setDirty.

What is the deadline for release of the functionality?

a couple of days perhaps.

I look forward, thanks.

I love the idea of helper methods on the field object.

I added:

  • reset: resets the flags for the specified field, if no arguments were provided it will reset all fields' flags.
  • setValid: sets the valid flag for a specified field and updates its computed flags (failed, and passed).
  • setDirty: sets the dirty flag for a specified and updates its computed flags (failed, passed, and clean).
  • dirty: gets the dirty flag for the specified field, if no arguments were provided it checks if at least one field is dirty.
  • clean: same as dirty, if no arguments were provided it checks if all fields are clean.
  • valid: same as dirty. if no arguemts were provided it checks if all fields are valid.
  • passed: same as dirty. if no arguments were provided it will check if all fields have passed.
  • failed: same as dirty. if no arguments were provided it will check if at least one field has failed.

@BrandonSurowiec @xereda I'm open to suggests for other methods you guys might find useful. But I'm closing this since I implemented some already.

Very good! Already been released?

It's not released yet.

It will be added in the documentation?

Yep, sorry about that I'm having trouble finding the time for it, should be up later today.

@xereda should be updated now.

Hi @logaretm !
Seems that you've removed that dirty getter from fields API, but it is really much concise and cleaner then the way you suggest here.
Shall we expect that method to come back one day?

Hi @logaretm. No more support for dirty?

Was this page helpful?
0 / 5 - 0 ratings