diff --git a/resources/assets/js/components/AkauntingItemButton.vue b/resources/assets/js/components/AkauntingItemButton.vue index fec7ddd20..7ed6378e6 100644 --- a/resources/assets/js/components/AkauntingItemButton.vue +++ b/resources/assets/js/components/AkauntingItemButton.vue @@ -345,13 +345,13 @@ export default { onItemSelected(item) { const indexeditem = { ...item, index: this.currentIndex }; - this.addItem(indexeditem); + this.addItem(indexeditem, 'oldItem'); }, - addItem(item) { + addItem(item, itemType) { this.selected_items.push(item); - this.$emit('item', item); + this.$emit('item', { item, itemType } ); this.$emit('items', this.selected_items); this.show.item_selected = false; @@ -380,7 +380,7 @@ export default { ? item = this.item_list[0] : this.newItems.push(item) - this.addItem(item); + this.addItem(item, 'newItem'); }, onSubmit(event) { diff --git a/resources/assets/js/views/common/documents.js b/resources/assets/js/views/common/documents.js index 4059f9fdd..c39dc05c4 100644 --- a/resources/assets/js/views/common/documents.js +++ b/resources/assets/js/views/common/documents.js @@ -97,6 +97,14 @@ const app = new Vue({ }, methods: { + onRefFocus(ref, index) { + ref + ? ref === 'price' + ? setPromiseTimeout(100).then(() => this.$refs[ref][0].$children[0].$el.focus()) + : setPromiseTimeout(100).then(() => this.$refs[ref][index].focus()) + : {} + }, + onCalculateTotal() { let global_discount = parseFloat(this.form.discount); let discount_total = 0; @@ -303,12 +311,14 @@ const app = new Vue({ }, // addItem to list - onAddItem(item) { + onAddItem(payload) { + let { item, itemType } = payload let { index } = item; + let inputRef = `${itemType === 'newItem' ? 'name' : 'description'}`; // indication for which input to focus first let total = 1 * item.price; let item_taxes = []; - - setPromiseTimeout(200).then(() => this.$refs['name-input'][index].focus()); //add focus to new item name input + + this.onRefFocus(inputRef, index); // trigger initial focus event on input if (item.tax_ids) { item.tax_ids.forEach(function (tax_id, index) { diff --git a/resources/views/components/documents/form/line-item.blade.php b/resources/views/components/documents/form/line-item.blade.php index e93ff799c..762569005 100644 --- a/resources/views/components/documents/form/line-item.blade.php +++ b/resources/views/components/documents/form/line-item.blade.php @@ -34,7 +34,7 @@ @stack('name_input_start') - + @change="form.errors.clear('items.' + index + '.name')" + @keydown.enter="onRefFocus('description', index)">
@@ -59,6 +59,7 @@ @if (!$hideDescription) @endif @@ -81,6 +84,7 @@ - + @change="form.errors.clear('items.' + index + '.quantity')" + @keydown.enter="onRefFocus('price', index)">
@@ -105,7 +109,7 @@ @if (!$hidePrice)
@stack('price_input_start') - {{ Form::moneyGroup('price', '', '', ['required' => 'required', 'row-input' => 'true', 'v-model' => 'row.price', 'v-error' => 'form.errors.get(\'items.\' + index + \'.price\')', 'v-error-message' => 'form.errors.get(\'items.\' + index + \'.price\')' , 'data-item' => 'price', 'currency' => $currency, 'dynamic-currency' => 'currency', 'change' => 'row.price = $event; form.errors.clear(\'items.\' + index + \'.price\'); onCalculateTotal'], 0.00, 'text-right input-price p-0') }} + {{ Form::moneyGroup('price', '', '', ['required' => 'required', 'inputRef' => 'price', 'row-input' => 'true', 'v-model' => 'row.price', 'v-error' => 'form.errors.get(\'items.\' + index + \'.price\')', 'v-error-message' => 'form.errors.get(\'items.\' + index + \'.price\')' , 'data-item' => 'price', 'currency' => $currency, 'dynamic-currency' => 'currency', 'change' => 'row.price = $event; form.errors.clear(\'items.\' + index + \'.price\'); onCalculateTotal'], 0.00, 'text-right input-price p-0') }} @stack('price_input_end')
@endif diff --git a/resources/views/partials/form/money_group.blade.php b/resources/views/partials/form/money_group.blade.php index fca3dfa66..e67f17818 100644 --- a/resources/views/partials/form/money_group.blade.php +++ b/resources/views/partials/form/money_group.blade.php @@ -27,6 +27,10 @@ v-if="{{ $attributes['show'] }}" @endif + @if (isset($attributes['inputRef'])) + ref="{{ $attributes['inputRef'] }}" + @endif + @if (isset($attributes['masked'])) :masked="{{ ($attributes['masked']) ? 'true' : 'false' }}" @endif @@ -74,6 +78,7 @@ @if (isset($attributes['row-input'])) :row-input="{{ $attributes['row-input'] }}" @endif + > @stack($name . '_input_end')