Vue.component('WarehouseArticlePacket', { //language=Vue template: ` `, data() { return { window: window, historyModal: false, historyModalId: null, subItemsAutocomplete: '', articles: [], updateCounter: 0, newSubItemAmount: 1, subItems: [] } }, beforeMount() { this.articles = window['TT_CONFIG']['CRUD_CONFIG'].columns.find(column => column.key === 'subItems').modal.items; }, methods: { updateCrudModalData() { const ref = this.$refs.WarehouseArticlePacketCrud; ref.$set(ref.crudModalData, 'subItems', JSON.stringify(this.subItems)); this.updateCounter++; }, removeSubItem(item) { this.subItems = this.subItems.filter(subItem => subItem !== item); this.updateCrudModalData(); }, addSubItem() { // only continue if id and amount are set else use window.notify('error', 'Bitte Artikel und Menge auswählen'); if (this.subItemsAutocomplete === '' || this.newSubItemAmount === '') { window.notify('error', 'Bitte Artikel und Menge auswählen'); return; } this.subItems.push({id: this.subItemsAutocomplete, amount: this.newSubItemAmount}); this.updateCrudModalData(); this.$refs.subItemsAutocomplete.clear(); this.newSubItemAmount = 1; } }, mounted() { this.$watch(() => { return this.$refs.WarehouseArticlePacketCrud.crudModal }, () => { // check if this.$refs.WarehouseArticlePacketCrud.crudModalData.subItems is defined if (typeof this.$refs.WarehouseArticlePacketCrud.crudModalData.subItems === 'undefined') { this.$set(this.$refs.WarehouseArticlePacketCrud.crudModalData, 'subItems', JSON.stringify([])); } this.subItems = JSON.parse(this.$refs.WarehouseArticlePacketCrud.crudModalData.subItems); }) } })