Update forms to handle a dynamic schema prop
This commit is contained in:
parent
9aa03c39ba
commit
fa70eb540a
|
@ -1,6 +1,7 @@
|
||||||
<script>
|
<script>
|
||||||
import { getContext, onMount } from "svelte"
|
import { getContext, onMount } from "svelte"
|
||||||
import InnerForm from "./InnerForm.svelte"
|
import InnerForm from "./InnerForm.svelte"
|
||||||
|
import { hashString } from "utils/helpers"
|
||||||
|
|
||||||
export let dataSource
|
export let dataSource
|
||||||
export let theme
|
export let theme
|
||||||
|
@ -15,6 +16,8 @@
|
||||||
let schema
|
let schema
|
||||||
let table
|
let table
|
||||||
|
|
||||||
|
$: fetchSchema(dataSource)
|
||||||
|
|
||||||
// Returns the closes data context which isn't a built in context
|
// Returns the closes data context which isn't a built in context
|
||||||
const getInitialValues = (type, dataSource, context) => {
|
const getInitialValues = (type, dataSource, context) => {
|
||||||
// Only inherit values for update forms
|
// Only inherit values for update forms
|
||||||
|
@ -35,7 +38,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetches the form schema from this form's dataSource
|
// Fetches the form schema from this form's dataSource
|
||||||
const fetchSchema = async () => {
|
const fetchSchema = async dataSource => {
|
||||||
if (!dataSource) {
|
if (!dataSource) {
|
||||||
schema = {}
|
schema = {}
|
||||||
}
|
}
|
||||||
|
@ -62,14 +65,15 @@
|
||||||
schema = dataSourceSchema || {}
|
schema = dataSourceSchema || {}
|
||||||
}
|
}
|
||||||
|
|
||||||
loaded = true
|
if (!loaded) {
|
||||||
|
loaded = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$: initialValues = getInitialValues(actionType, dataSource, $context)
|
$: initialValues = getInitialValues(actionType, dataSource, $context)
|
||||||
$: resetKey = JSON.stringify(initialValues)
|
$: resetKey = hashString(
|
||||||
|
JSON.stringify(initialValues) + JSON.stringify(schema)
|
||||||
// Load the form schema on mount
|
)
|
||||||
onMount(fetchSchema)
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if loaded}
|
{#if loaded}
|
||||||
|
|
Loading…
Reference in New Issue