added new fail validation callback
This commit is contained in:
@@ -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");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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",
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user