vue-material/src/components/mdInputContainer/common.js

58 lines
1.3 KiB
JavaScript
Raw Normal View History

export default {
props: {
value: [String, Number],
disabled: Boolean,
required: Boolean,
2016-11-14 20:53:06 +00:00
maxlength: [Number, String],
placeholder: String
},
watch: {
value() {
this.setParentValue();
},
disabled() {
this.setParentDisabled();
},
required() {
this.setParentRequired();
},
placeholder() {
this.setParentPlaceholder();
},
maxlength() {
this.handleMaxLength();
}
},
methods: {
handleMaxLength() {
this.parentContainer.enableCounter = this.maxlength > 0;
this.parentContainer.counterLength = this.maxlength;
},
setParentValue() {
this.parentContainer.setValue(this.value);
},
setParentDisabled() {
this.parentContainer.isDisabled = this.disabled;
},
setParentRequired() {
this.parentContainer.isRequired = this.required;
},
setParentPlaceholder() {
this.parentContainer.hasPlaceholder = !!this.placeholder;
},
onFocus() {
this.parentContainer.isFocused = true;
},
onBlur() {
this.parentContainer.isFocused = false;
this.setParentValue();
},
onInput() {
this.setParentValue();
this.parentContainer.inputLength = this.value.length;
this.$emit('change', this.value);
this.$emit('input', this.value);
}
}
};