<form @submit.prevent="login">
<input type="email" v-model="form.email"/>
<div class="invalid-feedback d-flex" v-if="form.errors.email">
{{ form.errors.email }}
</div>
<input type="password" v-model="form.password" />
<div class="invalid-feedback d-flex" v-if="form.errors.password">
{{ form.errors.password }}
</div>
<button type="submit" >Login</button>
</form>
const form = useForm({
email: null,
password: null,
});
return { form };
},
methods: {
login() {
this.form
.transform((data) => ({
...data,
remember: this.form.remember ? "on" : "",
}))
.post(this.route("login"), {
onFinish: () => this.form.reset("password"),
onSuccess: () => {
this.$swal({
icon: "success",
title: "Login Successfully",
showConfirmButton: false,
timer: 1500,
});
},
});
},
},
Dec 29, 2021
7
Level 6
How to reset password field after validation fails with inertia
Hi guys, I'm learning the inertia.js series. I want to clear password field after validation fails. I've tried onError, onFinish and onSuccess. But these're not working as I expected. Please would you help me....๐ข๐ข
Login.vue
<script>
import { useForm } from "@inertiajs/inertia-vue3";
export default {
layout: null,
setup() {
const form = useForm({
email: "",
password: "",
});
const submit = () => {
form.post("login", form, {
// not working ๐ข
onError: () => form.reset("password"),
// not working ๐ข
onFinish: () => form.reset("password"),
// not working ๐ข
onSuccess: () => form.reset("password"),
});
};
return { form, submit };
},
};
</script>
Please or to participate in this conversation.