Changeset View
Changeset View
Standalone View
Standalone View
src/resources/vue/Widgets/ListInput.vue
Show All 40 Lines | export default { | ||||
}, | }, | ||||
methods: { | methods: { | ||||
addItem(focus) { | addItem(focus) { | ||||
let value = this.input.value | let value = this.input.value | ||||
if (value) { | if (value) { | ||||
this.list.push(value) | this.list.push(value) | ||||
this.input.value = '' | this.input.value = '' | ||||
this.input.classList.remove('is-invalid') | |||||
if (focus !== false) { | if (focus !== false) { | ||||
this.input.focus() | this.input.focus() | ||||
} | } | ||||
if (this.list.length == 1) { | |||||
this.$el.classList.remove('is-invalid') | |||||
} | |||||
} | } | ||||
}, | }, | ||||
deleteItem(index) { | deleteItem(index) { | ||||
this.$delete(this.list, index) | this.$delete(this.list, index) | ||||
if (this.list.length == 1) { | if (!this.list.length) { | ||||
$(this.$el).removeClass('is-invalid') | this.$el.classList.remove('is-invalid') | ||||
} | } | ||||
}, | }, | ||||
keyDown(e) { | keyDown(e) { | ||||
if (e.which == 13 && e.target.value) { | if (e.which == 13 && e.target.value) { | ||||
this.addItem() | this.addItem() | ||||
e.preventDefault() | e.preventDefault() | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
</script> | </script> |