diff --git a/packages/builder/src/components/design/PropertiesPanel/PropertyControls/ValidationEditor/ValidationDrawer.svelte b/packages/builder/src/components/design/PropertiesPanel/PropertyControls/ValidationEditor/ValidationDrawer.svelte index b769e1f60e..70f9afe65a 100644 --- a/packages/builder/src/components/design/PropertiesPanel/PropertyControls/ValidationEditor/ValidationDrawer.svelte +++ b/packages/builder/src/components/design/PropertiesPanel/PropertyControls/ValidationEditor/ValidationDrawer.svelte @@ -7,11 +7,14 @@ Select, Heading, Body, + Input, + DatePicker, } from "@budibase/bbui" import { currentAsset, selectedComponent } from "builderStore" import { findClosestMatchingComponent } from "builderStore/storeUtils" import { getSchemaForDatasource } from "builderStore/dataBinding" import DrawerBindableInput from "components/common/bindings/DrawerBindableInput.svelte" + import { generate } from "shortid" export let rules = [] export let bindings = [] @@ -100,10 +103,11 @@ $: dataSourceSchema = getDataSourceSchema($currentAsset, $selectedComponent) $: field = $selectedComponent?.field $: schemaRules = parseRulesFromSchema(field, dataSourceSchema || {}) - $: constraintOptions = getConstraintsForType(type) + $: fieldType = type?.split("/")[1] || "string" + $: constraintOptions = getConstraintsForType(fieldType) const getConstraintsForType = type => { - return ConstraintMap[type?.split("/")[1] || "string"] + return ConstraintMap[type] } const getDataSourceSchema = (asset, component) => { @@ -145,7 +149,7 @@ const length = constraints.length.maximum rules.push({ constraint: "maxLength", - constraintValue: length, + value: length, error: `Maximum ${length} characters`, }) } @@ -155,7 +159,7 @@ const min = constraints.numericality.greaterThanOrEqualTo rules.push({ constraint: "minValue", - constraintValue: min, + value: min, error: `Minimum value is ${min}`, }) } @@ -163,7 +167,7 @@ const max = constraints.numericality.lessThanOrEqualTo rules.push({ constraint: "maxValue", - constraintValue: max, + value: max, error: `Maximum value is ${max}`, }) } @@ -176,7 +180,14 @@ } const addRule = () => { - rules = [...(rules || []), {}] + rules = [ + ...(rules || []), + { + valueType: "Binding", + type: fieldType, + id: generate(), + }, + ] } const removeRule = id => { @@ -199,9 +210,15 @@ options={constraintOptions} disabled /> + - (rule.constraintValue = e.detail)} + placeholder={null} + bind:value={rule.valueType} + options={["Binding", "Value"]} /> + {#if rule.valueType === "Binding"} + (rule.value = e.detail)} + /> + {:else if ["string", "number", "options", "longform"].includes(rule.type)} + + {:else if fieldType === "boolean"} +