This repository has been archived by the owner on Apr 2, 2022. It is now read-only.
/
control-field-extend-mixin.js
101 lines (88 loc) · 2.19 KB
/
control-field-extend-mixin.js
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/**
* Base Setup for any `controls` of Control in Vue-Form-Builder
* @example InputControl - use the mixin. I'll keep our code extendable as possible
*/
import {STYLE_INJECTION_MIXIN} from "@/mixins/style-injection-mixin";
const EMIT_EVENT = "change";
const CONTROL_FIELD_EXTEND_MIXIN = {
mixins: [STYLE_INJECTION_MIXIN],
props: {
// control configuration
control: {
type: Object,
required: true
},
// v-model value
value: null, // any types
},
// global data-field - available to override
data: () =>({
stopDefaultValueAssign: false
}),
/**
* For V-Model Purpose
* Basically, we will emit the 'change' to the parent to keep the update...
*/
model: {
event: EMIT_EVENT,
props: "value"
},
watch: {
/**
* Watch if there is new data being assigned
* @param val
*/
value(val) {
this.setValue(val)
}
},
methods: {
/**
* Run this to emit the value to the parent
* @param val
*/
updateValue(val) {
this.$emit(EMIT_EVENT, val)
},
/**
* Need-To-Override Method - Set Value.
* Set value from parent to the current field/control
*/
setValue(val) {return val} // NEED TO OVERRIDE
},
computed: {
/**
* Class for Field (input)
* @returns {(string)[]}
*/
controlFieldClass() {
return [
this.styles.FORM.FORM_CONTROL,
this.control.additionalFieldClass
]
},
/**
* Control Name
* @returns {*|string|string}
*/
controlName() {
return this.control.name || this.control.uniqueId
}
},
/**
* Global post-mounted processing
*/
mounted() {
// default set value
if (
this.stopDefaultValueAssign === false &&
!this.value &&
this.control.defaultValue
) {
this.updateValue(this.control.defaultValue)
}
},
}
export {
CONTROL_FIELD_EXTEND_MIXIN
}