2
0
mirror of https://github.com/tenrok/vue-select.git synced 2026-06-22 10:30:34 +03:00

value prop no longer has a required type, can accept null values

This commit is contained in:
Jeff Sagal
2016-03-08 14:26:59 -08:00
parent d182caa6b1
commit 9981742f52
3 changed files with 68 additions and 39 deletions
+39 -21
View File
File diff suppressed because one or more lines are too long
+4 -4
View File
@@ -54,7 +54,7 @@
<label class="control-label"> <label class="control-label">
<input v-model="multiple" type="checkbox"> Multiple <input v-model="multiple" type="checkbox"> Multiple
</label> </label>
<span class="help-block">Equivalent to the <code>multiple</code> attribute to a <code>&#x3C;select&#x3E;</code></span> <span class="help-block">Equivalent to the <code>multiple</code> attribute to a <code>&#x3C;select&#x3E;</code>. You'll want to clear any selections you have made before changing this option. It's not one that should be changed after render.</span>
</div> </div>
<div class="form-group"> <div class="form-group">
@@ -94,10 +94,10 @@ export default {
// select: [{label: 'This is Foo', value: 'foo'}, {label: 'This is Bar', value: 'bar'}], // select: [{label: 'This is Foo', value: 'foo'}, {label: 'This is Bar', value: 'bar'}],
select: null, select: null,
placeholder: 'Choose a Country', placeholder: 'Choose a Country',
multiple: false, multiple: true,
maxHeight: '400px', maxHeight: '400px',
// options: require('./countries.js') options: require('./countries.js')
options: ['one','two','three'] // options: ['one','two','three']
// options: [{label: 'This is Foo', value: 'foo'}, {label: 'This is Bar', value: 'bar'}, {label: 'This is Baz', value: 'baz'}] // options: [{label: 'This is Foo', value: 'foo'}, {label: 'This is Bar', value: 'bar'}, {label: 'This is Baz', value: 'baz'}]
} }
} }
+25 -14
View File
@@ -117,7 +117,7 @@
{{ placeholder }} {{ placeholder }}
</span> </span>
<span class="alert alert-info" v-for="option in value"> <span class="alert alert-info" v-for="option in valueAsArray">
{{ getOptionLabel(option) }} {{ getOptionLabel(option) }}
<button v-if="multiple" @click="select(option)" type="button" class="close"> <button v-if="multiple" @click="select(option)" type="button" class="close">
<span aria-hidden="true">&times;</span> <span aria-hidden="true">&times;</span>
@@ -211,24 +211,25 @@
} }
}); });
}, },
watch: {
value (val, oldVal) {
// return this.$set('value', ['test'])
}
},
methods: { methods: {
select(v) { select(option) {
if (this.value.indexOf(v) === -1) { if (! this.isOptionSelected(option) ) {
if (this.multiple) { if (this.multiple) {
this.value.push(v)
// check if value is currently null/undefined/false
if( ! this.value ) {
this.$set('value', [option])
} else {
this.value.push(option)
}
} else { } else {
this.value = [v] this.value = option
} }
} else { } else {
if (this.multiple) { if (this.multiple) {
this.value.$remove(v) this.value.$remove(option)
} }
} }
@@ -244,7 +245,7 @@
}, },
isOptionSelected( option ) { isOptionSelected( option ) {
if( this.multiple ) { if( this.multiple && this.value ) {
return this.value.indexOf(option) !== -1 return this.value.indexOf(option) !== -1
} }
@@ -314,6 +315,16 @@
} }
return true; return true;
},
valueAsArray() {
if( this.multiple ) {
return this.value
} else if (this.value) {
return [this.value]
}
return []
} }
} }