Programmatically trigger submit #3094
Answered
by
logaretm
vedran-milic
asked this question in
Q&A
-
Is there a way to programmatically trigger submit event from outside the Form component? <Form
@submit="submitForm"
v-slot="{ errors }"
class="form tiny-input change-password-form"
:initial-values="userData.data"
ref="profileUpdateForm"
novalidate
>
<div class="form-group input">
<label class="tiny-label bg">First name</label>
<Field
name="first_name"
as="input"
type="text"
rules="required"
:disabled="submitting"
/>
<span class="error-message" v-if="errors.first_name">
{{ errors.first_name }}
</span>
</div>
<div class="form-group input">
<label class="tiny-label bg">Last name</label>
<Field
name="last_name"
as="input"
type="text"
rules="required"
:disabled="submitting"
/>
<span class="error-message" v-if="errors.last_name">
{{ errors.last_name }}
</span>
</div>
<div class="form-group input">
<label class="tiny-label bg">Email</label>
<Field
name="email"
as="input"
type="email"
rules="required|email"
:disabled="submitting"
/>
<span class="error-message" v-if="errors.email">
{{ errors.email }}
</span>
</div>
<div class="form-group input">
<label class="tiny-label bg">Username</label>
<Field
name="username"
as="input"
type="text"
rules="required"
:disabled="submitting"
/>
<span class="error-message" v-if="errors.username">
{{ errors.username }}
</span>
</div>
</Form>
<!-- some more code -->
<!-- some more code -->
<!-- some more code -->
<!-- some more code -->
<template v-slot:footer>
<div class="submit-action" v-if="hasData && editing">
<button class="btn rounded light" @click="triggerSubmitFromHere">
Save changes
</button>
</div>
</template> Button is not "nested" inside Form tag. |
Beta Was this translation helpful? Give feedback.
Answered by
logaretm
Dec 21, 2020
Replies: 1 comment 1 reply
-
I moved this to the discussions section as this is not an issue, but rather a question. To answer your question, this is not a limitation from vee-validate's side, there are multiple ways you can submit a form outside of it. Two ways that come to mind are the |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
logaretm
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I moved this to the discussions section as this is not an issue, but rather a question.
To answer your question, this is not a limitation from vee-validate's side, there are multiple ways you can submit a form outside of it. Two ways that come to mind are the
button
element'sform
attribute ordispatchEvent
on the form element itself which can be triggered with$refs
.