vue-material/src/core/utils/autocomplete-commons.js

60 lines
1.3 KiB
JavaScript
Raw Normal View History

2017-04-04 02:00:42 +00:00
export default {
props: {
debounce: {
type: Number,
default: 1E3
},
disabled: Boolean,
fetch: {
type: Function
},
filterList: Function,
list: {
type: Array,
default() {
return [];
}
},
minChars: {
type: Number,
default: 1
},
name: String,
prepareResponseData: Function,
printAttribute: {
type: String,
default: 'name'
},
queryParam: {
type: String,
default: 'q'
},
required: Boolean,
value: Array
},
methods: {
onFocus() {
if (this.parentContainer) {
this.parentContainer.isFocused = true;
}
},
onBlur() {
this.parentContainer.isFocused = false;
this.setParentValue();
},
verifyProps() {
if (!this.parentContainer) {
return this.throwErrorDestroy('You should wrap the md-input in a md-input-container');
} else if (!this.listIsEmpty && this.filterList) {
return this.throwErrorDestroy('You should use a `filterList` function prop with the `list` prop');
} else if (!this.fetch) {
return this.throwErrorDestroy('You should use a `fetch` function prop');
}
},
throwErrorDestroy(errorMessage) {
this.$destroy();
throw new Error(errorMessage);
}
}
};