Skip to content

Commit

Permalink
Add unique ref for focus events
Browse files Browse the repository at this point in the history
  • Loading branch information
benguozakinci@gmail.com authored and benguozakinci@gmail.com committed Sep 2, 2021
1 parent a05763f commit 808306a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
9 changes: 3 additions & 6 deletions resources/assets/js/components/AkauntingItemButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,8 @@ export default {
onItemSelected(clickSelectedItem) {
let item;
const firstMatchedItem = this.item_list[0];
const isClickSelectedItem = clickSelectedItem ? true : false;
isClickSelectedItem ? item = clickSelectedItem : item = firstMatchedItem;
const indexeditem = { ...item, index: this.currentIndex };
this.addItem(indexeditem, 'oldItem');
Expand All @@ -383,7 +380,7 @@ export default {
onItemCreate() {
let item = {
index: this.newItems.length,
index: this.currentIndex,
key: 0,
value: this.search,
type: this.type,
Expand All @@ -394,7 +391,7 @@ export default {
tax_ids: [],
};
this.newItems.push(item)
this.newItems.push(item);
this.addItem(item, 'newItem');
},
Expand Down Expand Up @@ -528,7 +525,7 @@ export default {
return this.sortItems();
},
currentIndex() {
return this.selected_items.length;
return this.$root.form.items.length;
},
},
Expand Down
22 changes: 16 additions & 6 deletions resources/assets/js/views/common/documents.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const app = new Vue({
discounts: [],
tax_id: [],
items: [],
selected_items:[],
taxes: [],
page_loaded: false,
currencies: [],
Expand Down Expand Up @@ -96,8 +97,10 @@ const app = new Vue({
},

methods: {
onRefFocus(ref, index) {
setPromiseTimeout(100).then(() => this.$refs[ref][index].focus());
onRefFocus(ref) {
let index = this.form.items.length - 1;

this.$refs['items-' + index + '-' + ref][0].focus();
},

onCalculateTotal() {
Expand Down Expand Up @@ -305,15 +308,16 @@ const app = new Vue({
return totals_taxes;
},

onSelectedItem(item){
this.onAddItem(item);
},

// addItem to list
onAddItem(payload) {
let { item, itemType } = payload
let { index } = item;
let { item, itemType } = payload;
let inputRef = `${itemType === 'newItem' ? 'name' : 'description'}`; // indication for which input to focus first
let total = 1 * item.price;
let item_taxes = [];

this.onRefFocus(inputRef, index); // trigger initial focus event on input or description based on type of item added to the list

if (item.tax_ids) {
item.tax_ids.forEach(function (tax_id, index) {
Expand Down Expand Up @@ -359,8 +363,14 @@ const app = new Vue({
// invoice_item_checkbox_sample: [],
});

setTimeout(function() {
this.onRefFocus(inputRef);
}.bind(this), 100);

setTimeout(function() {
this.onCalculateTotal();

this.onRefFocus(inputRef);
}.bind(this), 800);
},

Expand Down
6 changes: 3 additions & 3 deletions resources/views/components/documents/form/line-item.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
@stack('name_input_start')
<input
type="text"
ref="name"
:ref="'items-' + index + '-name'"
class="form-control"
:name="'items.' + index + '.name'"
autocomplete="off"
Expand All @@ -58,7 +58,7 @@ class="form-control"
@if (!$hideDescription)
<textarea
class="form-control"
ref="description"
:ref="'items-' + index + '-description'"
placeholder="{{ trans('items.enter_item_description') }}"
style="height: 46px; overflow: hidden;"
:name="'items.' + index + '.description'"
Expand All @@ -81,7 +81,7 @@ class="form-control"
<input
type="number"
min="0"
ref="quantity"
:ref="'items-' + index + '-quantity'"
class="form-control text-center p-0 input-number-disabled"
:name="'items.' + index + '.quantity'"
autocomplete="off"
Expand Down
2 changes: 1 addition & 1 deletion resources/views/components/select-item-button.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
:dynamic-currency="currency"
:items="{{ json_encode($items) }}"
:search-char-limit="{{ $searchCharLimit }}"
@item="onAddItem($event)"
@item="onSelectedItem($event)"
add-item-text="{{ trans('general.form.add_an', ['field' => trans_choice('general.items', 1)]) }}"
create-new-item-text="{{ trans('general.title.create', ['type' => trans_choice('general.items', 1)]) }}"
></akaunting-item-button>

0 comments on commit 808306a

Please sign in to comment.