forked from area17/twill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCheckboxGroup.vue
executable file
·97 lines (88 loc) · 2.44 KB
/
CheckboxGroup.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
87
88
89
90
91
92
93
94
95
96
97
<template>
<a17-inputframe :error="error" :note="note" :label="label" :name="name">
<ul class="checkboxGroup" :class="checkboxClasses">
<li class="checkboxGroup__item" v-for="checkbox in options" :key="checkbox.value">
<a17-checkbox :name="name" :value="checkbox.value" :label="checkbox.label" @change="changeValue" :initialValue="currentValue" :disabled="checkbox.disabled || disabled"></a17-checkbox>
</li>
</ul>
</a17-inputframe>
</template>
<script>
import isEqual from 'lodash/isEqual'
import InputframeMixin from '@/mixins/inputFrame'
import CheckboxMixin from '@/mixins/checkboxes'
import FormStoreMixin from '@/mixins/formStore'
export default {
name: 'A17CheckboxGroup',
props: {
name: {
type: String,
default: ''
},
inline: {
type: Boolean,
default: false
},
options: {
type: Array,
default: function () { return [] }
}
},
mixins: [InputframeMixin, CheckboxMixin, FormStoreMixin],
computed: {
checkboxClasses: function () {
return [
this.inline ? 'checkboxGroup--inline' : ''
]
}
},
methods: {
formatValue: function (newVal, oldval) {
const self = this
if (!newVal) return
if (!oldval) return
const isMax = this.isMax(newVal) // defined in the checkboxes mixin
const isMin = this.isMin(newVal) // defined in the checkboxes mixin
if (isMax || isMin) {
if (!isEqual(oldval, self.checkedValue)) {
self.checkedValue = oldval
}
}
},
updateFromStore: function (newValue) { // called from the formStore mixin
this.updateValue(newValue)
},
updateValue: function (newValue) {
this.checkedValue = newValue
},
changeValue: function (newValue) {
if (!isEqual(newValue, this.currentValue)) {
this.updateValue(newValue)
}
}
},
mounted: function () {
if ((this.max + this.min) > 0) {
this.$watch('currentValue', this.formatValue, {
immediate: true
})
}
}
}
</script>
<style lang="scss" scoped>
.checkboxGroup {
color:$color__text;
}
.checkboxGroup--inline {
display:flex;
flex-flow: row wrap;
overflow:hidden;
}
.checkboxGroup--inline .checkboxGroup__item {
margin-right:20px;
}
.checkboxGroup__item {
padding:7px 0 8px 0;
}
</style>