forked from vue-generators/vue-form-generator
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfieldSubmit.vue
45 lines (40 loc) · 1.48 KB
/
fieldSubmit.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<template lang="pug">
input(:id="fieldID", type="submit", :value="fieldOptions.buttonText", @click="onClick", :name="inputName", :disabled="disabled", :class="fieldClasses", v-attributes="'input'")
</template>
<script>
import abstractField from "../abstractField";
import { isFunction, isEmpty } from "lodash";
export default {
name: "field-submit",
mixins: [abstractField],
methods: {
onClick($event) {
if (this.fieldOptions.validateBeforeSubmit === true) {
// prevent a <form /> from having it's submit event triggered
// when we have to validate data first
$event.preventDefault();
this.eventBus.$emit("fields-validation-trigger");
this.eventBus.$on("fields-validation-terminated", (formErrors) => {
if (!isEmpty(formErrors) && isFunction(this.fieldOptions.onValidationError)) {
this.fieldOptions.onValidationError(this.model, this.schema, formErrors, $event);
} else if (isFunction(this.fieldOptions.onSubmit)) {
this.fieldOptions.onSubmit(this.model, this.schema, $event);
}
});
} else if (isFunction(this.fieldOptions.onSubmit)) {
// if we aren't validating, just pass the onSubmit handler the $event
// so it can be handled there
this.fieldOptions.onSubmit(this.model, this.schema, $event);
}
}
}
};
</script>
<style lang="scss">
.vue-form-generator .field-submit input {
// Default bootstrap primary button style
color: #fff !important;
background-color: #337ab7 !important;
border-color: #2e6da4 !important;
}
</style>