Skip to content

Commit a8cc160

Browse files
committed
clear input container state if model is falsy
1 parent aa3f95e commit a8cc160

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

src/components/mdInputContainer/common.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ export default {
77
placeholder: String
88
},
99
watch: {
10-
value(value) {
11-
this.setParentValue(value);
12-
this.updateValues(value);
10+
value() {
11+
this.updateValues();
1312
},
1413
disabled() {
1514
this.setParentDisabled();
@@ -41,11 +40,13 @@ export default {
4140
setParentPlaceholder() {
4241
this.parentContainer.hasPlaceholder = !!this.placeholder;
4342
},
44-
updateValues(value) {
45-
const newValue = value || this.$el.value || this.value;
43+
updateValues() {
44+
this.$nextTick(() => {
45+
const newValue = this.$el.value || this.value;
4646

47-
this.setParentValue(newValue);
48-
this.parentContainer.inputLength = newValue ? newValue.length : 0;
47+
this.setParentValue(newValue);
48+
this.parentContainer.inputLength = newValue ? newValue.length : 0;
49+
});
4950
},
5051
onFocus() {
5152
if (this.parentContainer) {

src/components/mdInputContainer/mdInput.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
throw new Error('You should wrap the md-input in a md-input-container');
3838
}
3939
40+
this.parentContainer.inputInstance = this;
4041
this.setParentDisabled();
4142
this.setParentRequired();
4243
this.setParentPlaceholder();

src/components/mdInputContainer/mdInputContainer.vue

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
return {
3333
value: '',
3434
input: false,
35+
inputInstance: null,
3536
showPassword: false,
3637
enableCounter: false,
3738
hasSelect: false,
@@ -85,11 +86,9 @@
8586
}
8687
},
8788
clearInput() {
88-
if (this.isInput()) {
89-
this.input.value = '';
90-
this.setValue(this.input.value);
91-
this.$emit('input', this.input.value);
92-
}
89+
this.inputInstance.$el.value = '';
90+
this.inputInstance.$emit('input', '');
91+
this.setValue('');
9392
},
9493
setValue(value) {
9594
this.value = value;

src/components/mdInputContainer/mdTextarea.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
throw new Error('You should wrap the md-textarea in a md-input-container');
3737
}
3838
39+
this.parentContainer.inputInstance = this;
3940
this.setParentDisabled();
4041
this.setParentRequired();
4142
this.setParentPlaceholder();

0 commit comments

Comments
 (0)