no longer error on init then search then tab off without selecting

This commit is contained in:
2020-03-24 18:56:06 +00:00
parent 88338fa7b3
commit 21295dbe98
2 changed files with 69 additions and 15 deletions

View File

@@ -10,7 +10,7 @@
item-value="id" item-value="id"
item-disabled="!active" item-disabled="!active"
:error-messages="errors" :error-messages="errors"
:loading="searchUnderway" :loading="fetching"
:placeholder="lt('Search')" :placeholder="lt('Search')"
:search-input.sync="searchEntry" :search-input.sync="searchEntry"
:multiple="multiple" :multiple="multiple"
@@ -21,7 +21,7 @@
:prepend-icon="errorIcon" :prepend-icon="errorIcon"
@click:prepend="handleErrorClick" @click:prepend="handleErrorClick"
@mousedown="dropdown" @mousedown="dropdown"
auto-select-first cache-items
> >
<template v-slot:prepend-item v-if="hasError()"> <template v-slot:prepend-item v-if="hasError()">
<div class="pl-2"> <div class="pl-2">
@@ -66,6 +66,8 @@ DROP DOWN
PRE-FILL PRE-FILL
NO prefill, fills only on user action or with defaults to save bandwidth. User must drop down to initiate action or type search text NO prefill, fills only on user action or with defaults to save bandwidth. User must drop down to initiate action or type search text
todo: search entry, should preserve preset value until it's changed or maybe keep until the form is reloaded so can be inserted back again in search results
todo: set actual seleted ID value from our local selected whole object so outer form just gets id todo: set actual seleted ID value from our local selected whole object so outer form just gets id
todo: server sends whole on drop down of empty combo? todo: server sends whole on drop down of empty combo?
todo: needs to fill in the selected value when the form opens regardless of what any other setting is, todo: needs to fill in the selected value when the form opens regardless of what any other setting is,
@@ -110,7 +112,8 @@ export default {
searchResults: [], searchResults: [],
errors: [], errors: [],
searchEntry: null, searchEntry: null,
searchUnderway: false, lastSelection: null,
fetching: false,
isTagFilter: false, isTagFilter: false,
errorIcon: null, errorIcon: null,
initialized: false initialized: false
@@ -139,8 +142,7 @@ export default {
searchEntry(val, oldVal) { searchEntry(val, oldVal) {
var vm = this; var vm = this;
//clear any local errors //clear any local errors
vm.errors = []; vm.clearErrors();
//if the search entry is in the results list then it's a drop down selection not a typed search so bail //if the search entry is in the results list then it's a drop down selection not a typed search so bail
for (var i = 0; i < vm.searchResults.length; i++) { for (var i = 0; i < vm.searchResults.length; i++) {
if (vm.searchResults[i].name == val) { if (vm.searchResults[i].name == val) {
@@ -148,7 +150,13 @@ export default {
} }
} }
if (!val || vm.searchUnderway || !vm.initialized) { console.log(
"watch:searchentry cleared check to see if it's a selected list item, doing search for ",
val
);
console.log("search results:", vm.searchResults);
if (!val || vm.fetching || !vm.initialized) {
if (!vm.initialized) { if (!vm.initialized) {
vm.$nextTick(() => { vm.$nextTick(() => {
vm.initialized = true; vm.initialized = true;
@@ -158,7 +166,6 @@ export default {
} }
this.doSearch(); this.doSearch();
}, },
errors(val) { errors(val) {
if (this.hasError()) { if (this.hasError()) {
this.errorIcon = "fa-question-circle"; this.errorIcon = "fa-question-circle";
@@ -174,6 +181,9 @@ export default {
hasError: function() { hasError: function() {
return this.errors.length > 0; return this.errors.length > 0;
}, },
clearErrors: function() {
this.errors = [];
},
handleErrorClick: function() { handleErrorClick: function() {
//open help nav for picklist //open help nav for picklist
window.$gz.eventBus.$emit("menu-click", { window.$gz.eventBus.$emit("menu-click", {
@@ -182,6 +192,7 @@ export default {
}); });
}, },
selectionMade(e) { selectionMade(e) {
this.clearErrors();
if (e == undefined) { if (e == undefined) {
//this will happen when clear clicked //this will happen when clear clicked
return; return;
@@ -189,9 +200,49 @@ export default {
if (e.id != null) { if (e.id != null) {
this.$emit("input", e.id); this.$emit("input", e.id);
} }
this.lastSelection = e;
},
replaceLastSelection() {
console.log("replace last selection top");
var vm = this;
//check if searchREsults has last selection, if not then add it back in again
if (vm.lastSelection == null) {
//it might be initializing
for (var i = 0; i < vm.searchResults.length; i++) {
if (vm.searchResults[i].id == vm.value) {
console.log(
"rpl last selection null but found in list so setting last selection"
);
vm.lastSelection = vm.searchResults[i];
return;
}
}
console.log("RPL bailing as last selection is null and not in list");
return;
}
for (var i = 0; i < vm.searchResults.length; i++) {
if (vm.searchResults[i].id == vm.lastSelection.id) {
console.log("replacelastselection bailing, it's in list already");
return;
}
}
vm.searchResults.push(vm.lastSelection);
console.log(
"replacelastselection bottom, search results now:",
vm.searchResults
);
}, },
dropdown(e) { dropdown(e) {
//console.log("DROPDOWN FIRED", e); var vm = this;
//check if we have only the initial loaded item and no selection item
if (vm.searchResults.length < 3) {
//get the default list
vm.getList();
}
}, },
customFilter(item, queryText, itemText) { customFilter(item, queryText, itemText) {
//NOTE: I wanted this to work with tags but all it does is highlight all of each row if tag query is present //NOTE: I wanted this to work with tags but all it does is highlight all of each row if tag query is present
@@ -218,6 +269,10 @@ export default {
}, },
getList: function(urlParams) { getList: function(urlParams) {
var vm = this; var vm = this;
if (vm.fetching) {
return;
}
vm.fetching = true;
// console.log("getlist: calling api.get.picklist for type ", vm.ayaType); // console.log("getlist: calling api.get.picklist for type ", vm.ayaType);
//default params for when called on init //default params for when called on init
if (!urlParams) { if (!urlParams) {
@@ -229,18 +284,17 @@ export default {
window.$gz.api window.$gz.api
.get("PickList/List" + urlParams) .get("PickList/List" + urlParams)
.then(res => { .then(res => {
vm.fetching = false;
if (res.error) { if (res.error) {
throw res.error; throw res.error;
} }
vm.searchResults = res.data; vm.searchResults = res.data;
window.$gz.form.addNoSelectionItem(vm.searchResults); window.$gz.form.addNoSelectionItem(vm.searchResults);
vm.replaceLastSelection();
vm.searchUnderway = false;
}) })
.catch(err => { .catch(err => {
window.$gz.errorHandler.handleFormError(err); window.$gz.errorHandler.handleFormError(err);
vm.fetching = false;
}); });
}, },
doSearch: _.debounce(function() { doSearch: _.debounce(function() {
@@ -314,7 +368,7 @@ export default {
} }
//build url //build url
vm.searchUnderway = true; //vm.fetching = true;
var urlParams = "?ayaType=" + vm.ayaType; var urlParams = "?ayaType=" + vm.ayaType;
if (!emptyQuery) { if (!emptyQuery) {

View File

@@ -7,12 +7,12 @@
> >
</gz-pick-list> </gz-pick-list>
<v-divider></v-divider> <v-divider></v-divider>
<gz-pick-list <!-- <gz-pick-list
v-model="selectedUser" v-model="selectedUser"
:ayaType="ayaType().User" :ayaType="ayaType().User"
:label="lt('User')" :label="lt('User')"
> >
</gz-pick-list> </gz-pick-list> -->
<v-divider></v-divider> <v-divider></v-divider>
<div>FORM Selected Widget: {{ selectedWidget }}</div> <div>FORM Selected Widget: {{ selectedWidget }}</div>
<div>FORM Selected User: {{ selectedUser }}</div> <div>FORM Selected User: {{ selectedUser }}</div>