fix: Make Autocomplete option cache like link field (#23888)
* fix: execute query even though input cache exists * fix: remove invalid autocomplete caching This cache can get stale when document value changes. --------- Co-authored-by: Shankar <Shankarv19bcr> Co-authored-by: Ankush Menat <ankush@frappe.io>
This commit is contained in:
parent
4e188ec531
commit
b58f6a7420
1 changed files with 1 additions and 20 deletions
|
|
@ -85,33 +85,15 @@ frappe.ui.form.ControlAutocomplete = class ControlAutoComplete extends frappe.ui
|
|||
};
|
||||
}
|
||||
|
||||
init_option_cache() {
|
||||
if (!this.$input.cache) {
|
||||
this.$input.cache = {};
|
||||
}
|
||||
if (!this.$input.cache[this.doctype]) {
|
||||
this.$input.cache[this.doctype] = {};
|
||||
}
|
||||
if (!this.$input.cache[this.doctype][this.df.fieldname]) {
|
||||
this.$input.cache[this.doctype][this.df.fieldname] = {};
|
||||
}
|
||||
}
|
||||
|
||||
setup_awesomplete() {
|
||||
this.awesomplete = new Awesomplete(this.input, this.get_awesomplete_settings());
|
||||
|
||||
$(this.input_area).find(".awesomplete ul").css("min-width", "100%");
|
||||
|
||||
this.init_option_cache();
|
||||
|
||||
this.$input.on(
|
||||
"input",
|
||||
frappe.utils.debounce((e) => {
|
||||
const cached_options =
|
||||
this.$input.cache[this.doctype][this.df.fieldname][e.target.value];
|
||||
if (cached_options && cached_options.length) {
|
||||
this.set_data(cached_options);
|
||||
} else if (this.get_query || this.df.get_query) {
|
||||
if (this.get_query || this.df.get_query) {
|
||||
this.execute_query_if_exists(e.target.value);
|
||||
} else {
|
||||
this.awesomplete.list = this.get_data();
|
||||
|
|
@ -245,7 +227,6 @@ frappe.ui.form.ControlAutocomplete = class ControlAutoComplete extends frappe.ui
|
|||
if (!this.$input.is(":focus")) {
|
||||
return;
|
||||
}
|
||||
this.$input.cache[this.doctype][this.df.fieldname][term] = message;
|
||||
this.set_data(message);
|
||||
},
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue