This repository has been archived by the owner on Apr 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
fieldElementCheckbox.vue
86 lines (84 loc) · 2.23 KB
/
fieldElementCheckbox.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
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
<template>
<el-form-item :label="schema.elementLabel ? schema.elementLabel : ''">
<el-checkbox
v-model="value"
:disabled="schema.disabled"
:autocomplete="schema.autocomplete"
:true-label="schema.checkedValue"
:false-label="schema.uncheckedValue"
:name="schema.inputName"
:id="schema.id"
:checked="checked"
>
</el-checkbox>
</el-form-item>
</template>
<script>
import { abstractField } from "vue-form-generator";
import { isBoolean } from "lodash";
export default {
name: "fieldElementCheckbox",
mixins: [abstractField],
data: () => ({
checked: false
}),
mounted() {
this.checkedValue();
},
methods: {
checkedValue() {
if (
this.schema.hasOwnProperty("default") &&
this.schema.hasOwnProperty("checkedValue")
) {
if (
this.schema.default === this.schema.checkedValue ||
this.schema.default === true
) {
this.value = this.schema.checkedValue;
this.checked = true;
return;
}
}
if (
this.schema.hasOwnProperty("default") &&
this.schema.hasOwnProperty("uncheckedValue")
) {
if (
this.schema.default === this.schema.uncheckedValue ||
this.schema.default === false
) {
this.value = this.schema.uncheckedValue;
this.checked = false;
return;
}
}
if (
this.schema.hasOwnProperty("default") &&
this.schema.hasOwnProperty("uncheckedValue") &&
this.schema.hasOwnProperty("checkedValue")
) {
if (
this.schema.default !== this.schema.uncheckedValue &&
this.schema.default !== this.schema.checkedValue
) {
this.value = this.schema.uncheckedValue;
this.checked = false;
return;
}
}
if (this.schema.hasOwnProperty("default")) {
if (isBoolean(this.schema.default)) {
this.value = this.schema.default;
this.checked = this.schema.default;
return;
}
}
this.value = this.schema.hasOwnProperty("uncheckedValue")
? this.schema.uncheckedValue
: false;
this.checked = false;
}
}
};
</script>