From 9d0a3354c0b903673d9eccc206656728511f6ef7 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Thu, 19 Mar 2020 15:16:04 +0000 Subject: [PATCH] --- ayanova/src/components/pick-list.vue | 74 +++++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 2 deletions(-) diff --git a/ayanova/src/components/pick-list.vue b/ayanova/src/components/pick-list.vue index 7825e530..f44a0ee7 100644 --- a/ayanova/src/components/pick-list.vue +++ b/ayanova/src/components/pick-list.vue @@ -11,6 +11,7 @@ item-text="name" item-value="id" item-disabled="!active" + :error-messages="errors" :loading="searchUnderway" :placeholder="lt('search hint here')" :no-data-text="lt('NoData')" @@ -91,6 +92,7 @@ export default { data() { return { sourceresults: [], + errors: [], selected: { name: "-", id: 0 }, searchEntry: null, searchUnderway: false @@ -122,6 +124,9 @@ export default { watch: { searchEntry(val) { var vm = this; + //clear any local errors + vm.errors = []; + if (!val || vm.searchUnderway) { return; } @@ -131,9 +136,74 @@ export default { if (val == vm.selected.name) { return; } - //console.log("vm.selected=", vm.selected); - //debugger; } + + //Pre-process the query to validate and send conditionally + + //get the discrete search terms and verify there are max two + var isATwoTermQuery = false; + var queryTerms = []; + if (val.includes(" ")) { + queryTerms = val.split(" "); + if (queryTerms.length > 2) { + //todo: put client side localized validation error message in component + vm.errors.push("LTERROR TOO MANY TERMS"); + return; + } + isATwoTermQuery = true; + } else { + //one term only so push it into array + queryTerms.push(val); + //Marker term, will be weeded back out later + queryTerms.push("[?]"); + } + + //Now vet the terms + + //Is user in mid entry of a second tag (space only?) + //will appear as an empty string post split + if (queryTerms[1] == "") { + //mid entry of a second term, just return + return; + } + + //Is user in mid entry of tag query, just bounce back + if ( + queryTerms[0] == "." || + queryTerms[0] == ".." || + queryTerms[1] == "." || + queryTerms[1] == ".." + ) { + return; + } + + if (isATwoTermQuery) { + //check that both terms aren't tags + if ( + window.$gz._.startsWith(queryTerms[0], "..") && + window.$gz._.startsWith(queryTerms[1], "..") + ) { + //todo: put client side localized validation error message in component + vm.errors.push( + "LTERROR if two terms one must be tag and one must be text" + ); + return; + } + + //check that both aren't non-tags + if ( + !window.$gz._.startsWith(queryTerms[0], "..") && + !window.$gz._.startsWith(queryTerms[1], "..") + ) { + //todo: put client side localized validation error message in component + vm.errors.push( + "LTERROR if two terms one must be tag and one must be text" + ); + return; + } + } + + //QUERY IS VALID vm.searchUnderway = true; var urlParams = "?ayaType=" + vm.ayaType;