How to reset the form after submit and keep the validation
felipe-muner opened this issue · 2 comments
felipe-muner commented
Hello my friends...
I'm using vue-composable and everything is going well I did many different forms following the explanation..
My issue is how could I reset the form and keep the validation(very important)...
when i follow the code:
function buildValidation(){
return useValidation({....})
}
const form = ref(buildValidation());
function submit(){
form.value = buildValidation()
}
it works fine
but I don't know how to print the errors if some of them are invalid.
I had this before to print the errors:
const errorMessage = field =>
form[field].$dirty && form[field].$anyInvalid ? form[field].$errors[0] : ''
<v-field type="is-danger" label="Name" :message="errorMessage('name')" for="name">
<v-input type="text" id="name" v-model="form.name.$value" />
</v-field>
but I still don't know how to combine it...
thank you in advance
pikax commented
Added $touch/$reset
functions which will allow you to update the $dirty
negezor commented
The $dirty change will only happen once, after $reset() it won't work anymore.
vue-composable/packages/vue-composable/src/validation/validation.ts
Lines 239 to 246 in c7e7954