added new fail validation callback

This commit is contained in:
2023-02-28 19:42:25 +10:00
parent 35c3108db7
commit c83cfff556
3 changed files with 28 additions and 9 deletions

View File

@@ -22,7 +22,7 @@ const props = defineProps({
required: true,
},
});
const emits = defineEmits(["submit"]);
const emits = defineEmits(["submit", "failedValidation"]);
/**
* Handle the user submitting the form.
@@ -30,6 +30,8 @@ const emits = defineEmits(["submit"]);
const handleSubmit = async function () {
if (await props.modelValue.validate()) {
emits("submit");
} else {
emits("failedValidation");
}
};

View File

@@ -5,7 +5,10 @@
class="sm-page-event-edit">
<template #container>
<h1>{{ page_title }}</h1>
<SMForm :model-value="form" @submit="handleSubmit">
<SMForm
:model-value="form"
@submit="handleSubmit"
@failed-validation="handleFailValidation">
<SMRow>
<SMColumn><SMInput control="title" /></SMColumn>
</SMRow>
@@ -342,13 +345,16 @@ const handleSubmit = async () => {
router.push({ name: "dashboard-event-list" });
} catch (error) {
form.apiError(error);
form.apiErrors(error);
}
};
window.scrollTo({
top: 0,
left: 0,
behavior: "smooth",
const handleFailValidation = () => {
useToastStore().addToast({
title: "Save Error",
content:
"There are some errors in the form. Fix these before continuing.",
type: "danger",
});
};

View File

@@ -5,7 +5,10 @@
permission="admin/posts">
<template #container>
<h1>{{ page_title }}</h1>
<SMForm :model-value="form" @submit="handleSubmit">
<SMForm
:model-value="form"
@submit="handleSubmit"
@failed-validation="handleFailValidation">
<SMRow>
<SMColumn
><SMInput control="title" @blur="updateSlug()"
@@ -211,11 +214,19 @@ const handleSubmit = async () => {
router.push({ name: "dashboard-post-list" });
} catch (error) {
console.log(error);
form.apiErrors(error);
}
};
const handleFailValidation = () => {
useToastStore().addToast({
title: "Save Error",
content:
"There are some errors in the form. Fix these before continuing.",
type: "danger",
});
};
const createStorageKey = (file) => {
var date = new Date();
var day = date.toISOString().slice(0, 10);