This commit is contained in:
2020-03-24 00:13:15 +00:00
parent 2f84e06827
commit 3e82ca5a5b
2 changed files with 39 additions and 36 deletions

View File

@@ -1,7 +1,7 @@
<template> <template>
<div> <div>
<v-autocomplete <v-autocomplete
v-bind:value="value" v-model="value"
return-object return-object
:items="searchResults" :items="searchResults"
:label="label" :label="label"
@@ -12,7 +12,6 @@
:loading="searchUnderway" :loading="searchUnderway"
:placeholder="lt('Search')" :placeholder="lt('Search')"
:search-input.sync="searchEntry" :search-input.sync="searchEntry"
auto-select-first
:multiple="multiple" :multiple="multiple"
:filter="customFilter" :filter="customFilter"
hide-no-data hide-no-data
@@ -20,6 +19,7 @@
:no-filter="isTagFilter" :no-filter="isTagFilter"
:prepend-icon="errorIcon" :prepend-icon="errorIcon"
@click:prepend="handleErrorClick" @click:prepend="handleErrorClick"
auto-select-first
> >
<template v-slot:prepend-item v-if="hasError()"> <template v-slot:prepend-item v-if="hasError()">
<div class="pl-2"> <div class="pl-2">
@@ -27,7 +27,7 @@
</div> </div>
</template> </template>
</v-autocomplete> </v-autocomplete>
<!-- <div>autocomplete selected item: {{ selected }}</div> <!-- <div>autocomplete selected item: {{ selected }}</div> v-bind:value="value"
<div>searchResults: {{ searchResults }}</div> --> <div>searchResults: {{ searchResults }}</div> -->
</div> </div>
</template> </template>
@@ -58,11 +58,12 @@ todo: option to display icon to open the record selected, (we have the type and
export default { export default {
created() { created() {
var vm = this; var vm = this;
console.log("CREATED:value is ", this.value); // console.log("CREATED:value is ", this.value);
//need to add no selection object if specified //need to add no selection object if specified
if (vm.noSelectionValid) { if (vm.noSelectionValid) {
window.$gz.form.addNoSelectionItem(vm.searchResults); window.$gz.form.addNoSelectionItem(vm.searchResults);
// debugger; // debugger;
//TODO: this may be needed to force new records to have a zero in their no selection valid fields rather than null //TODO: this may be needed to force new records to have a zero in their no selection valid fields rather than null
// however it could overwrite a valid value maybe so needs further testing // however it could overwrite a valid value maybe so needs further testing
@@ -73,7 +74,7 @@ export default {
if (vm.value != null && vm.value != 0) { if (vm.value != null && vm.value != 0) {
//It has a prior non empty selection that needs to be fetched //It has a prior non empty selection that needs to be fetched
//note that by default this will just fetch the selected record instead of the prefill list //note that by default this will just fetch the selected record instead of the prefill list
console.log("STUB: created: has value, sb fetched"); // console.log("STUB: created: has value, sb fetched");
var urlParams = "?ayaType=" + vm.ayaType + "&preId=" + vm.value; var urlParams = "?ayaType=" + vm.ayaType + "&preId=" + vm.value;
vm.getList(urlParams); vm.getList(urlParams);
} else if (vm.preFill) { } else if (vm.preFill) {
@@ -82,17 +83,6 @@ export default {
vm.getList(); vm.getList();
} }
}, },
beforeUpdate() {
//Set the initial list items based on the record items, this only needs to be called once at init
//Not sure what this is to picklist as it came from tags
//console.log("beforeupdate: value is ", this.value);
if (!this.initialized && this.value && this.value != 0) {
//fetch here
this.initialized = true;
}
},
data() { data() {
return { return {
searchResults: [], searchResults: [],
@@ -133,12 +123,31 @@ export default {
label: { type: String, default: "" } label: { type: String, default: "" }
}, },
watch: { watch: {
searchEntry(val) { searchEntry(val, oldVal) {
var vm = this; var vm = this;
//clear any local errors //clear any local errors
vm.errors = []; vm.errors = [];
// console.log("WATCH::SEARCHENTRY TRIGGERED:", val); // console.log("WATCH::SEARCHENTRY TRIGGERED: initialized=", vm.initialized);
//if the selected search entry is in the results list then it's just a selection made manually
//console.log("watch:searchentry search results=", vm.searchResults);
for (var i = 0; i < vm.searchResults.length; i++) {
if (vm.searchResults[i].name == val) {
// console.log(
// "Search entry is in the search results so it was a seletion, bailing"
// );
return;
}
}
// console.log("val:", val);
// console.log("oldVal", oldVal);
if (!val || vm.searchUnderway || !vm.initialized) { if (!val || vm.searchUnderway || !vm.initialized) {
if (!vm.initialized) {
vm.$nextTick(() => {
vm.initialized = true;
});
}
return; return;
} }
if (vm.selected != null) { if (vm.selected != null) {
@@ -146,20 +155,22 @@ export default {
return; return;
} }
} }
// console.log("WATCH::SEARCHENTRY doing search now"); // debugger;
this.doSearch(); this.doSearch();
}, },
// value(val) { value(val) {
// //this ensures the parent form gets the onchange event //this ensures the parent form gets the onchange event
// //not actually sure why there are two here but it worked with the datetime picker so I replicated it here //not actually sure why there are two here but it worked with the datetime picker so I replicated it here
// //To answer above it appears both are necessary for proper operation //To answer above it appears both are necessary for proper operation
// this.$emit("input", val); this.$emit("input", val);
// this.$emit("change", val); this.$emit("change", val);
// }, console.log("Watch:Value triggered:", val);
},
selected(val) { selected(val) {
if (val && val.id) { if (val && val.id) {
console.log("Watch:Selected triggered:", val);
this.$emit("input", val.id); this.$emit("input", val.id);
//this.$emit("change", val.id); this.$emit("change", val.id);
} }
}, },
errors(val) { errors(val) {
@@ -227,10 +238,8 @@ export default {
vm.searchResults = res.data; vm.searchResults = res.data;
if (vm.noSelectionValid) { if (vm.noSelectionValid) {
window.$gz.form.addNoSelectionItem(vm.searchResults); window.$gz.form.addNoSelectionItem(vm.searchResults);
// if (vm.value == null) {
// vm.value = 0;
// }
} }
vm.searchUnderway = false; vm.searchUnderway = false;
}) })
.catch(err => { .catch(err => {
@@ -257,7 +266,6 @@ export default {
if (val.includes(" ")) { if (val.includes(" ")) {
queryTerms = val.split(" "); queryTerms = val.split(" ");
if (queryTerms.length > 2) { if (queryTerms.length > 2) {
//todo: put client side localized validation error message in component
vm.errors.push(vm.lt("ErrorPickListQueryInvalid")); vm.errors.push(vm.lt("ErrorPickListQueryInvalid"));
return; return;
} }
@@ -293,9 +301,7 @@ export default {
window.$gz._.startsWith(queryTerms[0], "..") && window.$gz._.startsWith(queryTerms[0], "..") &&
window.$gz._.startsWith(queryTerms[1], "..") window.$gz._.startsWith(queryTerms[1], "..")
) { ) {
//todo: put client side localized validation error message in component
vm.errors.push(vm.lt("ErrorPickListQueryInvalid")); vm.errors.push(vm.lt("ErrorPickListQueryInvalid"));
return; return;
} }
@@ -304,9 +310,7 @@ export default {
!window.$gz._.startsWith(queryTerms[0], "..") && !window.$gz._.startsWith(queryTerms[0], "..") &&
!window.$gz._.startsWith(queryTerms[1], "..") !window.$gz._.startsWith(queryTerms[1], "..")
) { ) {
//todo: put client side localized validation error message in component
vm.errors.push(vm.lt("ErrorPickListQueryInvalid")); vm.errors.push(vm.lt("ErrorPickListQueryInvalid"));
return; return;
} }
} }

View File

@@ -13,7 +13,6 @@
v-model="selectedUser" v-model="selectedUser"
:ayaType="ayaType().User" :ayaType="ayaType().User"
:label="lt('User')" :label="lt('User')"
:preFill="false"
> >
</gz-pick-list> </gz-pick-list>
<v-divider></v-divider> <v-divider></v-divider>