Prevent possible bugs on create item functionality

This commit is contained in:
benguozakinci@gmail.com
2021-09-02 12:00:19 +03:00
parent f0b37c3bc9
commit 5051d04e3e
2 changed files with 16 additions and 9 deletions

View File

@ -254,6 +254,8 @@ export default {
setItemList(items) { setItemList(items) {
this.item_list = []; this.item_list = [];
this.search.length === 0 ? this.isItemMatched = false : {}
// Option set sort_option data // Option set sort_option data
if (!Array.isArray(items)) { if (!Array.isArray(items)) {
let index = 0; let index = 0;
@ -299,6 +301,7 @@ export default {
}, },
onInput() { onInput() {
this.isItemMatched = false;
//to optimize performance we kept the condition that checks for if search exists or not //to optimize performance we kept the condition that checks for if search exists or not
if (!this.search) { if (!this.search) {
this.isItemMatched = false; //to remove the style from matched item on input is cleared (option) this.isItemMatched = false; //to remove the style from matched item on input is cleared (option)
@ -314,16 +317,14 @@ export default {
return; return;
} }
this.fetchMatchedItems(); this.fetchMatchedItems().then(() => this.item_list.length > 0 ? this.isItemMatched = true : this.isItemMatched = false );
this.item_list.length > 0
? this.isItemMatched = true
: {}
this.$emit('input', this.search); this.$emit('input', this.search);
this.isItemMatched === true && this.search.length > 0 ? this.isItemMatched = true : this.isItemMatched = true;
}, },
inputEnterEvent(event) { inputEnterEvent() {
this.isItemMatched this.isItemMatched
? this.onItemSelected() ? this.onItemSelected()
: this.onItemCreate() : this.onItemCreate()
@ -352,8 +353,14 @@ export default {
.catch(error => {}); .catch(error => {});
}, },
onItemSelected() { onItemSelected(clickSelectedItem) {
const item = this.item_list[0] let item;
const firstMatchedItem = this.item_list[0];
const isClickSelectedItem = clickSelectedItem ? true : false;
isClickSelectedItem ? item = clickSelectedItem : item = firstMatchedItem;
const indexeditem = { ...item, index: this.currentIndex }; const indexeditem = { ...item, index: this.currentIndex };
this.addItem(indexeditem, 'oldItem'); this.addItem(indexeditem, 'oldItem');

View File

@ -313,7 +313,7 @@ const app = new Vue({
let total = 1 * item.price; let total = 1 * item.price;
let item_taxes = []; let item_taxes = [];
this.onRefFocus(inputRef, index); // trigger initial focus event on input 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) { if (item.tax_ids) {
item.tax_ids.forEach(function (tax_id, index) { item.tax_ids.forEach(function (tax_id, index) {