-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Event listener for "invalid" is not working #8647
Comments
Not Vue-related, That event is fired in the input element, not the form element, and it doesn't bubble. So this works as expected: <template>
<form ref="form" @submit.prevent="handleSubmit">
<input @invalid="handleInvalid" required>
<button type="submit">Submit</button>
<p>{{ msg }}</p>
</form>
</template>
<script>
export default {
name: "HelloWorld",
data: () => ({
msg: 'Not validated yet'
}),
methods: {
handleSubmit() {
this.msg = 'submit event fired';
},
handleInvalid() {
this.msg = 'invalid event fired';
}
}
};
</script> |
Not true. If you manually addEventListener for invalid on form element it works correctly! |
This is link for vanilla and working javascript: https://codesandbox.io/s/3vl6rq4jmm |
You are missing the |
Yeah, posva beat me to it. Only works with capture since the event doesn't bubble. Should have thought of that solution first. |
Perfect, working as expected, thank you all. |
Version
2.5.17
Reproduction link
https://codesandbox.io/s/2p6zqqo75j
Steps to reproduce
When form is in invalid state no event handler is called
What is expected?
v-on:invalid should run the handler function
What is actually happening?
nothing
The text was updated successfully, but these errors were encountered: