Browse Source

Update forms to handle a dynamic schema prop

pull/3403/head
Andrew Kingston 5 years ago
parent
commit
fa70eb540a
  1. 16
      packages/client/src/components/app/forms/Form.svelte

16
packages/client/src/components/app/forms/Form.svelte

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

Loading…
Cancel
Save