From 8ab567e64c504a243f374a3468b52750b2f7fbe6 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Wed, 9 Jun 2021 12:29:27 +0100 Subject: [PATCH] Correctly set initial values when registering fields in forms --- .../standard-components/src/forms/Form.svelte | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/packages/standard-components/src/forms/Form.svelte b/packages/standard-components/src/forms/Form.svelte index d73af72a47..9a2c909385 100644 --- a/packages/standard-components/src/forms/Form.svelte +++ b/packages/standard-components/src/forms/Form.svelte @@ -42,18 +42,6 @@ // Auto columns are always disabled const isAutoColumn = !!schema?.[field]?.autocolumn - if (fieldMap[field] != null) { - // Update disabled property just so that toggling the disabled field - // state in the builder makes updates in real time. - // We only need this because of optimisations which prevent fully - // remounting when settings change. - fieldMap[field].fieldState.update(state => { - state.disabled = disabled || fieldDisabled || isAutoColumn - return state - }) - return fieldMap[field] - } - // Create validation function based on field schema const constraints = schema?.[field]?.constraints const validate = createValidatorFromConstraints(constraints, field, table) @@ -67,6 +55,10 @@ fieldApi: makeFieldApi(field, defaultValue, validate), fieldSchema: schema?.[field] ?? {}, } + + // Set initial value + fieldMap[field].fieldApi.setValue(defaultValue, true) + return fieldMap[field] }, validate: () => {