fix: getRow should be available in parent & child instances
This commit is contained in:
parent
5fcd447bc8
commit
d7e0eb09b3
@ -127,25 +127,23 @@ export function getScript(doctype, view = 'Form') {
|
|||||||
return meta[doctype]
|
return meta[doctype]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setupHelperMethods(FormClass, instance, parentInstance, document)
|
||||||
|
|
||||||
if (isChildDoctype) {
|
if (isChildDoctype) {
|
||||||
setupHelperMethods(FormClass, instance, document)
|
|
||||||
instance.doc = createDocProxy(document.doc, parentInstance)
|
instance.doc = createDocProxy(document.doc, parentInstance)
|
||||||
} else {
|
} else {
|
||||||
instance.doc = createDocProxy(document.doc, instance)
|
instance.doc = createDocProxy(document.doc, instance)
|
||||||
}
|
}
|
||||||
|
|
||||||
instance.actions = (instance.actions || []).filter(
|
|
||||||
(action) => typeof action.condition !== 'function' || action.condition(),
|
|
||||||
)
|
|
||||||
|
|
||||||
return instance
|
return instance
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupHelperMethods(FormClass, instance, document) {
|
function setupHelperMethods(FormClass, instance, parentInstance, document) {
|
||||||
FormClass.prototype.getRow = (parentField, idx) =>
|
if (typeof FormClass.prototype.getRow !== 'function') {
|
||||||
getRow(parentField, idx, document.doc, instance)
|
FormClass.prototype.getRow = (parentField, idx) =>
|
||||||
|
getRow(parentField, idx, document.doc, instance)
|
||||||
exposeHiddenMethods(document.doc, instance, ['getRow'])
|
}
|
||||||
|
exposeHiddenMethods(instance, parentInstance, ['getRow'])
|
||||||
}
|
}
|
||||||
|
|
||||||
function getRow(parentField, idx, data, instance) {
|
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) {
|
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
|
// Show as actual method on doc, bound to instance
|
||||||
Object.defineProperty(doc, name, {
|
Object.defineProperty(instance.doc, name, {
|
||||||
value: (...args) => instance[name](...args),
|
value: (...args) => instance[name](...args),
|
||||||
writable: false,
|
writable: false,
|
||||||
enumerable: false,
|
enumerable: false,
|
||||||
configurable: false,
|
configurable: true,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user