question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to reset only a single value on this.$validator.reset() event?

See original GitHub issue

Versions:

  • VueJs: 2.5.9
  • Vee-Validate: 2.0.0-rc.25

Description:

I have a single input and I want to reset only this

<input v-model.trim="role.Name" name="roleName">

But doesn’t works the code below

this.roleName.reset();

and I don’t want reset all inputs with

this.$validator.reset();

Its possible actually?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

22reactions
logaretmcommented, Dec 6, 2017

Call each.reset() and it should reset the flags and the classes, you would still need to remove the errors yourself though using validator.errors.remove.

You can also do this instead:

const matchOptions = {
  id: any, // if you have the id, otherwise its optional
  name: string, // optional
  scope: string // optional
};

const field = this.$validator.fields.find(matchOptions);
field.reset();
this.$validator.errors.remove(field.name, field.scope);

I know its not in the docs, We will fix that with the new docs. I just pushed an enhancement for this issue, should be up with the next release soon.

1reaction
amrut07commented, Aug 2, 2019

Hi below config worked for me.

const matchOptions = {
        //   // id: field.id, // if you have the id, otherwise its optional
          name: field.name, // optional
          scope: field.scope // optional
        }
        // required to check below condition as unnecessary validation functionality triggered even field has no errors!
        const errorField = _.find(this.$validator.errors.items, ['field', field.name]) ? this.$validator.fields.find(matchOptions) : false
        if (errorField) {
          `errorField.reset()`
          this.$validator.reset(errorField)
        }

By passing errorField in reset function reset that filed validation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is there a function in jquery.validate that will reset a single field ...
You can do the following to validate a single field: ... this will reset only the name element ... But it is not...
Read more >
Handling Forms - VeeValidate
Handling Forms. vee-validate offers many helpers to handle form submissions, resets, and DX to make your forms much easier to reason about and...
Read more >
FormControl - Angular
Resets the form control, marking it pristine and untouched , and resetting the value. The new value will be the provided value (if...
Read more >
reset - API Reference - Kendo UI Validator - Documentation
reset. Clears the registered errors and hides the validation messages and validation summary. Example - set sortable feature of the Grid to true....
Read more >
HTML DOM Form reset() Method - W3Schools
The reset() method resets the values of all elements in a form (same as clicking the Reset button). Tip: Use the submit() method...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found