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
+ }
-
- {#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'}
diff --git a/packages/builder/src/constants/backend/index.js b/packages/builder/src/constants/backend/index.js
index 7aec87bb4e..806f207572 100644
--- a/packages/builder/src/constants/backend/index.js
+++ b/packages/builder/src/constants/backend/index.js
@@ -3,6 +3,7 @@ export const FIELDS = {
name: "Plain Text",
icon: "ri-text",
type: "string",
+ value: "string",
constraints: {
type: "string",
length: {},
@@ -13,16 +14,18 @@ export const FIELDS = {
name: "Number",
icon: "ri-number-1",
type: "number",
+ value: "number",
constraints: {
type: "number",
presence: { allowEmpty: true },
- numericality: {},
+ numericality: { greaterThanOrEqualTo: "", lessThanOrEqualTo: "" },
},
},
BOOLEAN: {
name: "True/False",
icon: "ri-toggle-line",
type: "boolean",
+ value: "boolean",
constraints: {
type: "boolean",
presence: { allowEmpty: true },
@@ -41,10 +44,15 @@ export const FIELDS = {
name: "Date/Time",
icon: "ri-calendar-event-fill",
type: "string",
+ value: "datetime",
constraints: {
type: "string",
length: {},
presence: { allowEmpty: true },
+ datetime: {
+ latest: "",
+ earliest: "",
+ },
},
},
// IMAGE: {