prevent parent forms from submitting when adding chips #383

This commit is contained in:
Marcos Moura 2017-01-23 19:39:51 -02:00
parent d718749396
commit 4bbe83b6ad
4 changed files with 20 additions and 13 deletions

View file

@ -18,8 +18,8 @@
:name="mdInputName"
:disabled="disabled"
@keydown.native.delete="deleteLastChip"
@keydown.native.enter="selectChip"
@keydown.native.186="selectChip"
@keydown.native.prevent.enter="addChip"
@keydown.native.prevent.186="addChip"
tabindex="0"
ref="input">
</md-input>
@ -77,7 +77,7 @@
this.$refs.input.$el.focus();
});
},
selectChip() {
addChip() {
if (this.currentChip && this.selectedChips.length < this.mdMax) {
const value = this.currentChip.trim();

View file

@ -7,9 +7,9 @@ export default {
placeholder: String
},
watch: {
value() {
this.setParentValue(this.$el.value);
this.onInput();
value(value) {
this.setParentValue(value);
this.updateValues(value);
},
disabled() {
this.setParentDisabled();
@ -41,18 +41,25 @@ export default {
setParentPlaceholder() {
this.parentContainer.hasPlaceholder = !!this.placeholder;
},
updateValues(value) {
const newValue = value || this.$el.value || this.value;
this.setParentValue(newValue);
this.parentContainer.inputLength = newValue ? newValue.length : 0;
},
onFocus() {
this.parentContainer.isFocused = true;
if (this.parentContainer) {
this.parentContainer.isFocused = true;
}
},
onBlur() {
this.parentContainer.isFocused = false;
this.setParentValue();
},
onInput() {
this.setParentValue(this.value);
this.parentContainer.inputLength = this.value ? this.value.length : 0;
this.$emit('change', this.value);
this.$emit('input', this.value);
this.updateValues();
this.$emit('change', this.$el.value);
this.$emit('input', this.$el.value);
}
}
};

View file

@ -40,7 +40,7 @@
this.setParentRequired();
this.setParentPlaceholder();
this.handleMaxLength();
this.onInput();
this.updateValues();
});
}
};

View file

@ -39,7 +39,7 @@
this.setParentRequired();
this.setParentPlaceholder();
this.handleMaxLength();
this.onInput();
this.updateValues();
if (!this.$el.getAttribute('rows')) {
this.$el.setAttribute('rows', '1');