diff --git a/packages/builder/src/components/database/DataTable/modals/CreateEditColumn.svelte b/packages/builder/src/components/database/DataTable/modals/CreateEditColumn.svelte index b8eca01aad..f4c60fc8e1 100644 --- a/packages/builder/src/components/database/DataTable/modals/CreateEditColumn.svelte +++ b/packages/builder/src/components/database/DataTable/modals/CreateEditColumn.svelte @@ -15,22 +15,20 @@ import LinkedRecordSelector from "components/common/LinkedRecordSelector.svelte" import * as api from "../api" - export let onClosed - export let field = {} - let fieldDefinitions = cloneDeep(FIELDS) + + export let onClosed + export let field = { + type: "string", + constraints: fieldDefinitions.STRING.constraints, + } + let originalName = field.name $: required = field.constraints && field.constraints.presence && !field.constraints.presence.allowEmpty - $: if (field.type) { - field.constraints = merge( - fieldDefinitions[field.type.toUpperCase()].constraints, - field.constraints - ) - } async function saveColumn() { backendUiStore.update(state => { @@ -43,14 +41,26 @@ }) onClosed() } + + function handleFieldConstraints(event) { + const { type, constraints } = fieldDefinitions[ + event.target.value.toUpperCase() + ] + field.type = type + field.constraints = constraints + }
- {#each Object.values(fieldDefinitions) as field} - + {/each} @@ -63,28 +73,28 @@ on:change={() => (field.constraints.presence.allowEmpty = required)} />
- {#if field.type === 'string'} + {#if field.value === 'string' && field.constraints} - {:else if field.type === 'datetime'} + {:else if field.value === 'datetime' && field.constraints} - {:else if field.type === 'number'} + {:else if field.value === 'number' && field.constraints} - {:else if field.type === 'link'} + {:else if field.value === 'link'}