This commit is contained in:
2020-03-19 15:16:04 +00:00
parent 64fe2b4607
commit 9d0a3354c0

View File

@@ -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;