Ensure form doesn't inherit built in datasources

This commit is contained in:
Andrew Kingston 2021-02-16 15:30:20 +00:00
parent 6603e504b4
commit e0d1513af4
1 changed files with 9 additions and 1 deletions

View File

@ -18,8 +18,16 @@
let table let table
let fieldMap = {} let fieldMap = {}
// Returns the closes data context which isn't a built in context
const getInitialValues = context => {
if (["user", "url"].includes(context.closestComponentId)) {
return {}
}
return context[`${context.closestComponentId}`] || {}
}
// Use the closest data context as the initial form values // Use the closest data context as the initial form values
const initialValues = $context[`${$context.closestComponentId}`] || {} const initialValues = getInitialValues($context)
// Form state contains observable data about the form // Form state contains observable data about the form
const formState = writable({ values: initialValues, errors: {}, valid: true }) const formState = writable({ values: initialValues, errors: {}, valid: true })