FleetCart/Modules/Variation/Resources/assets/admin/js/create.js

69 lines
1.8 KiB
JavaScript
Raw Normal View History

2023-12-03 14:07:47 +00:00
import Vue from "vue";
import VariationMixin from "./mixins/VariationMixin";
import { toaster } from "@admin/js/Toaster";
new Vue({
el: "#app",
mixins: [VariationMixin],
created() {
this.setFormDefaultData();
},
mounted() {
this.focusInitialField();
},
methods: {
setFormDefaultData() {
this.form = {
uid: this.uid(),
type: "",
values: [
{
uid: this.uid(),
image: {
id: null,
path: null,
},
},
],
};
},
focusInitialField() {
this.$nextTick(() => {
$("#name").trigger("focus");
});
},
submit() {
this.formSubmitting = true;
$.ajax({
type: "POST",
url: route("admin.variations.store"),
data: this.transformData(this.form),
dataType: "json",
success: (response) => {
toaster(response.message, {
type: "success",
});
this.resetForm();
this.errors.reset();
},
})
.catch((error) => {
this.errors.reset();
this.errors.record(error.responseJSON.errors);
this.scrollToFirstErrorField(this.$refs.form.elements);
})
.always(() => {
this.formSubmitting = false;
});
},
},
});