From d7e0eb09b3b6c07cd465d899f7977832e3517d24 Mon Sep 17 00:00:00 2001 From: Shariq Ansari Date: Wed, 7 May 2025 12:14:47 +0530 Subject: [PATCH] fix: getRow should be available in parent & child instances --- frontend/src/data/script.js | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/frontend/src/data/script.js b/frontend/src/data/script.js index f4bbbdad..94d37064 100644 --- a/frontend/src/data/script.js +++ b/frontend/src/data/script.js @@ -127,25 +127,23 @@ export function getScript(doctype, view = 'Form') { return meta[doctype] } + setupHelperMethods(FormClass, instance, parentInstance, document) + if (isChildDoctype) { - setupHelperMethods(FormClass, instance, document) instance.doc = createDocProxy(document.doc, parentInstance) } else { instance.doc = createDocProxy(document.doc, instance) } - instance.actions = (instance.actions || []).filter( - (action) => typeof action.condition !== 'function' || action.condition(), - ) - return instance } - function setupHelperMethods(FormClass, instance, document) { - FormClass.prototype.getRow = (parentField, idx) => - getRow(parentField, idx, document.doc, instance) - - exposeHiddenMethods(document.doc, instance, ['getRow']) + function setupHelperMethods(FormClass, instance, parentInstance, document) { + if (typeof FormClass.prototype.getRow !== 'function') { + FormClass.prototype.getRow = (parentField, idx) => + getRow(parentField, idx, document.doc, instance) + } + exposeHiddenMethods(instance, parentInstance, ['getRow']) } function getRow(parentField, idx, data, instance) { @@ -220,15 +218,20 @@ export function getScript(doctype, view = 'Form') { }) } - function exposeHiddenMethods(doc, instance, methodNames = []) { + function exposeHiddenMethods(instance, parentInstance, methodNames = []) { for (const name of methodNames) { - if (typeof instance[name] === 'function') { + // remove the method from parent instance if it exists + if (parentInstance && parentInstance[name]) { + delete instance.doc[name] + } + + if (typeof instance[name] === 'function' && !instance.doc[name]) { // Show as actual method on doc, bound to instance - Object.defineProperty(doc, name, { + Object.defineProperty(instance.doc, name, { value: (...args) => instance[name](...args), writable: false, enumerable: false, - configurable: false, + configurable: true, }) } }