Files
Website/resources/js/components/SMForm.vue
2023-05-08 11:14:44 +10:00

37 lines
652 B
Vue

<template>
<form class="form" @submit.prevent="handleSubmit">
<slot></slot>
</form>
</template>
<script setup lang="ts">
import { provide } from "vue";
const props = defineProps({
modelValue: {
type: Object,
required: true,
},
});
const emits = defineEmits(["submit", "failedValidation"]);
/**
* Handle the user submitting the form.
*/
const handleSubmit = async function () {
if (await props.modelValue.validate()) {
emits("submit");
} else {
emits("failedValidation");
}
};
provide("form", props.modelValue);
</script>
<style lang="scss">
.form {
width: 100%;
}
</style>