From b58f6a7420bc8cd56c142cf391f76c23acfb2fa1 Mon Sep 17 00:00:00 2001 From: V Shankar Date: Mon, 8 Jan 2024 15:59:34 +0530 Subject: [PATCH] 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 Co-authored-by: Ankush Menat --- .../js/frappe/form/controls/autocomplete.js | 21 +------------------ 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/frappe/public/js/frappe/form/controls/autocomplete.js b/frappe/public/js/frappe/form/controls/autocomplete.js index 825cfb5320..b7bf5687d6 100644 --- a/frappe/public/js/frappe/form/controls/autocomplete.js +++ b/frappe/public/js/frappe/form/controls/autocomplete.js @@ -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); }, });