From 3b7d07834d8f4710e9d1ac5e3461d8118bea969b Mon Sep 17 00:00:00 2001 From: cmack Date: Thu, 20 Aug 2020 11:19:13 +0100 Subject: [PATCH] Unique field value property and event binding --- .../modals/CreateEditColumn.svelte | 40 ++++++++++++------- .../builder/src/constants/backend/index.js | 10 ++++- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/packages/builder/src/components/database/ModelDataTable/modals/CreateEditColumn.svelte b/packages/builder/src/components/database/ModelDataTable/modals/CreateEditColumn.svelte index b8eca01aad..f4c60fc8e1 100644 --- a/packages/builder/src/components/database/ModelDataTable/modals/CreateEditColumn.svelte +++ b/packages/builder/src/components/database/ModelDataTable/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'}