From 276bc18c32ab6f6d0d45d916704759b06ceca6af Mon Sep 17 00:00:00 2001 From: root Date: Thu, 16 Jul 2026 17:46:51 +0000 Subject: [PATCH] chore: fix WRONG FILE PATH - write JS to correct Frappe-resolved path (two-level-deep) with full customer clear + Description visible --- AGENTS.md | 2 +- .../engagement_card/engagement_card.js | 56 +++++++++++-------- 2 files changed, 33 insertions(+), 25 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 1014721..44c62a4 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1,6 +1,6 @@ # Service Factory — ERPNext Custom App Project -> **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. +> **Current Version: V0.1.0025** — 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 diff --git a/service_factory/service_factory/doctype/engagement_card/engagement_card.js b/service_factory/service_factory/doctype/engagement_card/engagement_card.js index fa1ea01..f2a5b73 100644 --- a/service_factory/service_factory/doctype/engagement_card/engagement_card.js +++ b/service_factory/service_factory/doctype/engagement_card/engagement_card.js @@ -1,5 +1,5 @@ // Copyright (c) 2026, cclohmar and contributors -// For license information, please see license.txt +// For license information, see please license.txt frappe.ui.form.on("Engagement Card", { onload: function (frm) { @@ -89,7 +89,6 @@ frappe.ui.form.on("Engagement Card", { }, // Re-filter opportunities when customer changes 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 () { let filters = {}; @@ -102,36 +101,45 @@ frappe.ui.form.on("Engagement Card", { }); function clear_customer_field(frm) { + if (!frm.is_new()) return; + // Prevent Frappe from caching this field's value across sessions - if (frappe.boot && frappe.boot.user && frappe.boot.user.last_selected_values) { + if (frappe.boot?.user?.last_selected_values) { delete frappe.boot.user.last_selected_values.Customer; } - // Model-level clear - frm.set_value("customer", null); + // Clear at the model level (direct, bypasses event triggers) + frm.doc.customer = null; - // Force-clear at the DOM and Awesomplete level after render is complete - setTimeout(() => { + // Also clear through Frappe's model API + frappe.model.set_value(frm.doctype, frm.docname, "customer", null); + + // Force-clear at the DOM and Awesomplete level repeatedly + // to catch any delayed re-population during form init + let attempts = 0; + const max_attempts = 10; + const timer = setInterval(() => { + attempts++; let field = frm.get_field("customer"); - if (!field) return; - - // Clear the input DOM value - if (field.$input) { - field.$input.val(""); + if (field) { + if (field.$input) { + field.$input.val(""); + } + if (field.awesomplete) { + field.awesomplete.index = -1; + field.awesomplete.selected = false; + field.awesomplete.autoFirst = false; + } + field.last_value = null; + field.value = null; } - - // 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; + if (frm.doc) { + frm.doc.customer = null; } - - // Reset field value tracking so blur handler sees no change - field.last_value = null; - field.value = null; - }, 200); + if (attempts >= max_attempts || !frm.is_new() || frm.doc.__islocal === 0) { + clearInterval(timer); + } + }, 150); } function load_select_options(frm) {