fix: provide array of instances in controllers if multiple script exist
(cherry picked from commit a2081da2960f35e7def0e670f396a9d82261af7d)
This commit is contained in:
parent
be3cf1f48c
commit
9b2f8dd7b5
@ -48,6 +48,7 @@ export function getScript(doctype, view = 'Form') {
|
|||||||
|
|
||||||
function setupMultipleFormControllers(scriptStrings, document, helpers) {
|
function setupMultipleFormControllers(scriptStrings, document, helpers) {
|
||||||
const controllers = {}
|
const controllers = {}
|
||||||
|
let parentInstanceIdx = null
|
||||||
|
|
||||||
for (let scriptName in scriptStrings) {
|
for (let scriptName in scriptStrings) {
|
||||||
let script = scriptStrings[scriptName]?.script
|
let script = scriptStrings[scriptName]?.script
|
||||||
@ -65,19 +66,34 @@ export function getScript(doctype, view = 'Form') {
|
|||||||
|
|
||||||
let { doctypeMeta } = getMeta(doctype)
|
let { doctypeMeta } = getMeta(doctype)
|
||||||
|
|
||||||
// if className is not doctype name, then it is a child doctype
|
if (!controllers[doctype]) {
|
||||||
let isChildDoctype = className !== doctypeName
|
controllers[doctype] = []
|
||||||
if (isChildDoctype) {
|
|
||||||
parentInstance = controllers[doctypeName]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
controllers[className] = setupFormController(
|
// if className is not doctype name, then it is a child doctype
|
||||||
|
let isChildDoctype = className !== doctypeName
|
||||||
|
|
||||||
|
if (isChildDoctype) {
|
||||||
|
if (!controllers[doctype].length) {
|
||||||
|
console.error(
|
||||||
|
`⚠️ No class found for doctype: ${doctype}, it is mandatory to have a class for the parent doctype. it can be empty, but it should be present.`,
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
parentInstance = controllers[doctype][parentInstanceIdx]
|
||||||
|
} else {
|
||||||
|
parentInstanceIdx = controllers[doctype].length || 0
|
||||||
|
}
|
||||||
|
|
||||||
|
const instance = setupFormController(
|
||||||
FormClass,
|
FormClass,
|
||||||
doctypeMeta,
|
doctypeMeta,
|
||||||
document,
|
document,
|
||||||
parentInstance,
|
parentInstance,
|
||||||
isChildDoctype,
|
isChildDoctype,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
controllers[doctype].push(instance)
|
||||||
})
|
})
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Failed to load form controller:', err)
|
console.error('Failed to load form controller:', err)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user