@@ -8,12 +8,17 @@ export default {
8
8
model: [String, Boolean, Object, Number, Array],
9
9
value: {
10
10
type: [String, Boolean, Object, Number],
11
-
default: 'on'
12
11
},
13
12
name: [String, Number],
14
13
required: Boolean,
15
14
disabled: Boolean,
16
-
indeterminate: Boolean
15
+
indeterminate: Boolean,
16
+
trueValue: {
17
+
default: true
18
+
},
19
+
falseValue: {
20
+
default: false
21
+
}
17
22
},
18
23
model: {
19
24
prop: 'model',
@@ -23,30 +28,48 @@ export default {
23
28
rippleActive: false
24
29
}),
25
30
computed: {
31
+
attrs () {
32
+
const attrs = {
33
+
id: this.id,
34
+
name: this.name,
35
+
disabled: this.disabled,
36
+
required: this.required,
37
+
'true-value': this.trueValue,
38
+
'false-value': this.falseValue
39
+
}
40
+
41
+
if (this.$options.propsData.hasOwnProperty('value')) {
42
+
if (this.value === null || typeof this.value !== 'object') {
43
+
attrs.value = (this.value === null || this.value === undefined) ? '' : String(this.value)
44
+
}
45
+
}
46
+
47
+
return attrs
48
+
},
26
49
isSelected () {
27
50
if (this.isModelArray) {
28
51
return this.model.includes(this.value)
29
52
}
30
53
31
-
if (this.isModelBoolean && this.value === 'on') {
32
-
return this.model
54
+
if (this.hasValue) {
55
+
return this.model === this.value
33
56
}
34
57
35
-
return this.model === this.value
58
+
return this.model === this.trueValue
36
59
},
37
60
isModelArray () {
38
61
return Array.isArray(this.model)
39
62
},
40
-
isModelBoolean () {
41
-
return typeof this.model === 'boolean'
42
-
},
43
63
checkClasses () {
44
64
return {
45
65
'md-checked': this.isSelected,
46
66
'md-disabled': this.disabled,
47
67
'md-required': this.required,
48
68
'md-indeterminate': this.indeterminate
49
69
}
70
+
},
71
+
hasValue () {
72
+
return this.$options.propsData.hasOwnProperty('value')
50
73
}
51
74
},
52
75
methods: {
@@ -68,26 +91,22 @@ export default {
68
91
69
92
this.$emit('change', newModel)
70
93
},
71
-
handleStringCheckbox () {
72
-
if (!this.isSelected) {
73
-
this.$emit('change', this.value)
74
-
} else {
75
-
this.$emit('change', null)
76
-
}
94
+
handleSingleSelectCheckbox () {
95
+
this.$emit('change', this.isSelected ? null : this.value)
77
96
},
78
-
handleBooleanCheckbox () {
79
-
this.$emit('change', !this.model)
97
+
handleSimpleCheckbox () {
98
+
this.$emit('change', this.isSelected ? this.falseValue : this.trueValue)
80
99
},
81
100
toggleCheck () {
82
101
if (!this.disabled) {
83
102
this.rippleActive = true
84
103
85
104
if (this.isModelArray) {
86
105
this.handleArrayCheckbox()
87
-
} else if (this.isModelBoolean) {
88
-
this.handleBooleanCheckbox()
106
+
} else if (this.hasValue) {
107
+
this.handleSingleSelectCheckbox()
89
108
} else {
90
-
this.handleStringCheckbox()
109
+
this.handleSimpleCheckbox()
91
110
}
92
111
}
93
112
}
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4