clear input container state if model is falsy

This commit is contained in:
Marcos Moura 2017-02-13 01:50:14 -02:00
parent aa3f95e036
commit a8cc1602d9
4 changed files with 14 additions and 12 deletions

View file

@ -7,9 +7,8 @@ export default {
placeholder: String
},
watch: {
value(value) {
this.setParentValue(value);
this.updateValues(value);
value() {
this.updateValues();
},
disabled() {
this.setParentDisabled();
@ -41,11 +40,13 @@ export default {
setParentPlaceholder() {
this.parentContainer.hasPlaceholder = !!this.placeholder;
},
updateValues(value) {
const newValue = value || this.$el.value || this.value;
updateValues() {
this.$nextTick(() => {
const newValue = this.$el.value || this.value;
this.setParentValue(newValue);
this.parentContainer.inputLength = newValue ? newValue.length : 0;
this.setParentValue(newValue);
this.parentContainer.inputLength = newValue ? newValue.length : 0;
});
},
onFocus() {
if (this.parentContainer) {

View file

@ -37,6 +37,7 @@
throw new Error('You should wrap the md-input in a md-input-container');
}
this.parentContainer.inputInstance = this;
this.setParentDisabled();
this.setParentRequired();
this.setParentPlaceholder();

View file

@ -32,6 +32,7 @@
return {
value: '',
input: false,
inputInstance: null,
showPassword: false,
enableCounter: false,
hasSelect: false,
@ -85,11 +86,9 @@
}
},
clearInput() {
if (this.isInput()) {
this.input.value = '';
this.setValue(this.input.value);
this.$emit('input', this.input.value);
}
this.inputInstance.$el.value = '';
this.inputInstance.$emit('input', '');
this.setValue('');
},
setValue(value) {
this.value = value;

View file

@ -36,6 +36,7 @@
throw new Error('You should wrap the md-textarea in a md-input-container');
}
this.parentContainer.inputInstance = this;
this.setParentDisabled();
this.setParentRequired();
this.setParentPlaceholder();