chore: force-clear customer field at Awesomplete/DOM level to prevent auto-selection
This commit is contained in:
parent
589f5437f1
commit
bab40d090d
2 changed files with 39 additions and 4 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
# Service Factory — ERPNext Custom App Project
|
# Service Factory — ERPNext Custom App Project
|
||||||
|
|
||||||
> **Current Version: V0.1.0023** — Each completed prompt/step increments the patch number by 1 (V0.1.0000 → V0.1.0001 → V0.1.0002…). The agent automatically commits and pushes after every step.
|
> **Current Version: V0.1.0024** — Each completed prompt/step increments the patch number by 1 (V0.1.0000 → V0.1.0001 → V0.1.0002…). The agent automatically commits and pushes after every step.
|
||||||
|
|
||||||
## Project Overview
|
## Project Overview
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ frappe.ui.form.on("Engagement Card", {
|
||||||
onload: function (frm) {
|
onload: function (frm) {
|
||||||
// Ensure customer starts empty on new forms
|
// Ensure customer starts empty on new forms
|
||||||
if (frm.is_new()) {
|
if (frm.is_new()) {
|
||||||
frm.set_value("customer", null);
|
clear_customer_field(frm);
|
||||||
}
|
}
|
||||||
load_select_options(frm);
|
load_select_options(frm);
|
||||||
toggle_creation_fields(frm);
|
toggle_creation_fields(frm);
|
||||||
|
|
@ -21,8 +21,8 @@ frappe.ui.form.on("Engagement Card", {
|
||||||
},
|
},
|
||||||
refresh: function (frm) {
|
refresh: function (frm) {
|
||||||
// Re-clear customer if awesomplete auto-selected on render
|
// Re-clear customer if awesomplete auto-selected on render
|
||||||
if (frm.is_new() && frm.doc.customer) {
|
if (frm.is_new()) {
|
||||||
frm.set_value("customer", null);
|
clear_customer_field(frm);
|
||||||
}
|
}
|
||||||
load_select_options(frm);
|
load_select_options(frm);
|
||||||
toggle_creation_fields(frm);
|
toggle_creation_fields(frm);
|
||||||
|
|
@ -89,6 +89,8 @@ frappe.ui.form.on("Engagement Card", {
|
||||||
},
|
},
|
||||||
// Re-filter opportunities when customer changes
|
// Re-filter opportunities when customer changes
|
||||||
customer: function (frm) {
|
customer: function (frm) {
|
||||||
|
// Clear the "auto-selected" flag so we don't block legitimate user selections
|
||||||
|
frm._cust_user_selected = true;
|
||||||
frm.set_query("opportunity", function () {
|
frm.set_query("opportunity", function () {
|
||||||
let filters = {};
|
let filters = {};
|
||||||
if (frm.doc.customer) {
|
if (frm.doc.customer) {
|
||||||
|
|
@ -99,6 +101,39 @@ frappe.ui.form.on("Engagement Card", {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function clear_customer_field(frm) {
|
||||||
|
// Prevent Frappe from caching this field's value across sessions
|
||||||
|
if (frappe.boot && frappe.boot.user && frappe.boot.user.last_selected_values) {
|
||||||
|
delete frappe.boot.user.last_selected_values.Customer;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Model-level clear
|
||||||
|
frm.set_value("customer", null);
|
||||||
|
|
||||||
|
// Force-clear at the DOM and Awesomplete level after render is complete
|
||||||
|
setTimeout(() => {
|
||||||
|
let field = frm.get_field("customer");
|
||||||
|
if (!field) return;
|
||||||
|
|
||||||
|
// Clear the input DOM value
|
||||||
|
if (field.$input) {
|
||||||
|
field.$input.val("");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset Awesomplete's internal selection state
|
||||||
|
if (field.awesomplete) {
|
||||||
|
field.awesomplete.index = -1;
|
||||||
|
field.awesomplete.selected = false;
|
||||||
|
// Disable autoFirst to prevent highlight-latching on first item
|
||||||
|
field.awesomplete.autoFirst = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset field value tracking so blur handler sees no change
|
||||||
|
field.last_value = null;
|
||||||
|
field.value = null;
|
||||||
|
}, 200);
|
||||||
|
}
|
||||||
|
|
||||||
function load_select_options(frm) {
|
function load_select_options(frm) {
|
||||||
frappe.call({
|
frappe.call({
|
||||||
method: "frappe.client.get",
|
method: "frappe.client.get",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue