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:
V Shankar 2024-01-08 15:59:34 +05:30 committed by GitHub
parent 4e188ec531
commit b58f6a7420
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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);
},
});