|
| 1 | +<template> |
| 2 | + <Multiselect |
| 3 | + :multiple="isMultiple" |
| 4 | + :options="schema.options || []" |
| 5 | + v-model="selected" |
| 6 | + track-by="value" |
| 7 | + label="label" |
| 8 | + @input="triggerChange" |
| 9 | + /> |
| 10 | +</template> |
| 11 | + |
| 12 | +<style lang="scss"> |
| 13 | +@import "vue-multiselect/dist/vue-multiselect.min.css"; |
| 14 | +
|
| 15 | +.field-multiselect { |
| 16 | + .multiselect { |
| 17 | + font-size: inherit; |
| 18 | +
|
| 19 | + .multiselect__element { |
| 20 | + margin-bottom: 0; |
| 21 | + } |
| 22 | +
|
| 23 | + .multiselect__tags { |
| 24 | + color: #555; |
| 25 | + border-color: #8c8f94; |
| 26 | + border-radius: 3px; |
| 27 | + &:hover { |
| 28 | + border-color: #999; |
| 29 | + } |
| 30 | + } |
| 31 | + .multiselect__input { |
| 32 | + font-size: inherit; |
| 33 | + border:none !important; |
| 34 | + background: transparent; |
| 35 | + box-shadow: none !important; |
| 36 | + padding: 0; |
| 37 | + outline: none !important; |
| 38 | + } |
| 39 | + .multiselect__content-wrapper { |
| 40 | + box-shadow: 0 3px 5px rgba(0,0,0,.2); |
| 41 | + border: 1px solid #ddd; |
| 42 | + border-radius: 0; |
| 43 | + margin-top: 5px; |
| 44 | + } |
| 45 | + .multiselect__option--highlight { |
| 46 | + background: #0073aa; |
| 47 | + color: #fff; |
| 48 | + &:after { |
| 49 | + background: #0073aa; |
| 50 | + color: #fff; |
| 51 | + } |
| 52 | + } |
| 53 | + .multiselect__tags-wrap { |
| 54 | + .multiselect__tag { |
| 55 | + background: #0085ba; |
| 56 | + border-radius: 3px; |
| 57 | + margin-bottom: 3px; |
| 58 | + padding: 5px 30px 5px 10px; |
| 59 | + i { |
| 60 | + border-radius: 0; |
| 61 | + &:hover { |
| 62 | + background: #dd3e3e; |
| 63 | + } |
| 64 | + } |
| 65 | + } |
| 66 | + } |
| 67 | + .multiselect__spinner { |
| 68 | + background: #f7f7f7; |
| 69 | + &:before, |
| 70 | + &:after { |
| 71 | + border-color: #0085ba transparent transparent |
| 72 | + } |
| 73 | + } |
| 74 | + .multiselect__single { |
| 75 | + background: transparent; |
| 76 | + font-size: inherit; |
| 77 | + } |
| 78 | + } |
| 79 | +} |
| 80 | +</style> |
| 81 | + |
| 82 | +<script> |
| 83 | +import Multiselect from 'vue-multiselect' |
| 84 | +
|
| 85 | +export default { |
| 86 | + props: { |
| 87 | + schema: {}, |
| 88 | + model: {}, |
| 89 | + formOptions: {}, |
| 90 | + disabled: false |
| 91 | + }, |
| 92 | + components: { |
| 93 | + Multiselect |
| 94 | + }, |
| 95 | + data() { |
| 96 | + return { |
| 97 | + selected: null, |
| 98 | + isMultiple: this.schema.multiple |
| 99 | + } |
| 100 | + }, |
| 101 | + methods: { |
| 102 | + clearValidationErrors(){ |
| 103 | +
|
| 104 | + }, |
| 105 | + validate(){ |
| 106 | +
|
| 107 | + }, |
| 108 | + triggerChange (value) { |
| 109 | +
|
| 110 | + let savedValue = value |
| 111 | +
|
| 112 | + if ( this.isMultiple === true ) { |
| 113 | + savedValue = [] |
| 114 | + value.forEach(function(element) { |
| 115 | + savedValue.push(element.value) |
| 116 | + }) |
| 117 | + } else if( savedValue === null ) { |
| 118 | + savedValue = null |
| 119 | + } else { |
| 120 | + savedValue = savedValue.value |
| 121 | + } |
| 122 | +
|
| 123 | + if( this.schema.model ){ |
| 124 | + this.$set( this.model, this.schema.model, savedValue ) |
| 125 | + } |
| 126 | +
|
| 127 | + this.$emit('input', savedValue ) |
| 128 | + } |
| 129 | + }, |
| 130 | + created() { |
| 131 | + let currentValue = this.model[this.schema.model]; |
| 132 | +
|
| 133 | + if( currentValue instanceof Array ){ |
| 134 | + currentValue = currentValue.map( role => this.schema.options.find( option => option.value == role ) ).filter( role => !!role ) |
| 135 | + }else if( typeof currentValue === 'string' ){ |
| 136 | + currentValue = this.schema.options.find( option => option.value == currentValue ) |
| 137 | + } |
| 138 | +
|
| 139 | + this.selected = currentValue; |
| 140 | + } |
| 141 | +} |
| 142 | +</script> |
0 commit comments