How can i get the values of forms programatically using template refs? #4112
Unanswered
gitamgadtaula
asked this question in
Q&A
Replies: 2 comments 2 replies
-
@logaretm Can you please please help me out ? |
Beta Was this translation helpful? Give feedback.
2 replies
-
Wondering why you need to call <template>
<Form @submit="onSubmit" :validation-schema="schema">
....
<button>Submit</button>
</Form>
</template>
<script setup>
import { Form, Field, ErrorMessage } from 'vee-validate';
import * as yup from 'yup';
const schema = yup.object({
email: yup.string().required().email(),
password: yup.string().required().min(8),
});
function onSubmit(values) {
// Submit values to API...
alert(JSON.stringify(values, null, 2));
} In any case, you can also get the values from the <template>
<Form ref="myForm" :validation-schema="schema">
...
</Form>
</template>
<script setup>
async function onSubmit() {
let validation = await this.$refs.myForm.validate();
if (validation.valid) {
const values = this.$refs.myForm.getValues();
sendRequest(this.$refs.myForm.values); // I need the values of form here, but somehow I can't
} else if (validation.errors) {
console.log(validation.errors);
}
}
</script> |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a custom validation trigger in my app using vue template refs. I can get to call the validate() method, but I can't seem to the get form values. Can anybody please point me to the right direction? I must be missing something, it should be pretty straightforward. I am asking this after days of constant reviewing the docs ending as a failure every-time.
Any help would be highly appreciated, thanks !
Beta Was this translation helpful? Give feedback.
All reactions