forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDialogSelect.vue
More file actions
107 lines (101 loc) · 2.33 KB
/
DialogSelect.vue
File metadata and controls
107 lines (101 loc) · 2.33 KB
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
102
103
104
105
106
107
<template>
<q-picker-textfield
:disable="disable"
:readonly="readonly"
:label="label"
:placeholder="placeholder"
:static-label="staticLabel"
:value="actualValue"
@click.native="pick"
@keydown.native.enter="pick"
></q-picker-textfield>
</template>
<script>
import Dialog from '../../components/dialog/dialog'
export default {
props: {
value: {
required: true
},
options: {
type: Array,
required: true,
validator (options) {
return !options.some(option =>
typeof option.label === 'undefined' || typeof option.value === 'undefined'
)
}
},
type: {
type: String,
required: true,
validator (value) {
return ['radio', 'checkbox', 'toggle'].includes(value)
}
},
okLabel: {
type: String,
default: 'OK'
},
cancelLabel: {
type: String,
default: 'Cancel'
},
title: {
type: String,
default: 'Select'
},
message: String,
label: String,
placeholder: String,
staticLabel: String,
readonly: Boolean,
disable: Boolean
},
computed: {
actualValue () {
if (this.type === 'radio') {
let option = this.options.find(option => option.value === this.value)
return option ? option.label : ''
}
let options = this.options
.filter(option => this.value.includes(option.value))
.map(option => option.label)
return !options.length ? '' : options.join(', ')
},
multipleSelection () {
return ['checkbox', 'toggle'].includes(this.type)
}
},
methods: {
pick () {
if (this.disable || this.readonly) {
return
}
let options = this.options.map(option => {
return {
value: option.value,
label: option.label,
model: this.multipleSelection ? this.value.includes(option.value) : this.value === option.value
}
})
Dialog.create({
title: this.title,
message: this.message,
form: {
select: {type: this.type, model: this.value, items: options}
},
buttons: [
this.cancelLabel,
{
label: this.okLabel,
handler: data => {
this.$emit('input', data.select)
}
}
]
})
}
}
}
</script>