Prevent vee-validate set dirty with data from API response

Viewed 377

My problem is that I need to prevent users from leave a page when the form is dirty and ask then if they want to save changes before leave. But, using vee-validate, the form is dirty when its filled with data from API response and I need to set the form dirty just when user change a value on form. I tried sets programmatically but the dirty remains true.

I also tried to use touched, but it seems not work with vue-multiselect

Maybe dirty its not exactly what I need, but the same problem happens using changed for example

This is how I tried to programmatically change the dirty state:

Object.keys(this.$refs.form.fields).forEach(
  (key) => (this.$refs.form.fields[key].dirty = false)
)

I also tried change only the form flag

this.$refs.form.flags.dirty = false

but without success

1 Answers

You can use resetForm

This will automatically set the dirty flag to false.

If you want to manipulate the form after you have set the values, you must use resetField

Related