1👍
✅
It is a good practice to move operations on component’s data to functions. You can achieve desired validation reset, by creating a resetValidation
function and binding it to focus event on input field.
Method itself should reset errors
field to falsy values. Example below assumes, there are multiple input fields in the form. Each field should call resetVlidation
method with corresponding error field name. If no field is provided, we can reset validation as whole:
resetValidation (field) {
if (field) {
this.errors = {
...this.errors,
[field]: ''
}
} else {
this.errors = {}
}
Please, check the working example below:
Source:stackexchange.com