From 725b9bb6e2e30f72ceca60a1f67581f075e6f7f4 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Wed, 25 Aug 2021 15:49:04 +0100 Subject: [PATCH] Add more validation options for array field --- .../ValidationEditor/ValidationDrawer.svelte | 35 +++++-- packages/builder/src/helpers/lucene.js | 2 +- .../src/api/controllers/row/internalSearch.js | 19 ++-- packages/server/src/db/views/staticViews.js | 11 ++- .../src/forms/MultiFieldSelect.svelte | 8 +- .../src/forms/optionsParser.js | 96 +++++++++---------- .../src/forms/validation.js | 39 ++++++-- 7 files changed, 131 insertions(+), 79 deletions(-) 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 e24a779b62..64938fe75b 100644 --- a/packages/builder/src/components/design/PropertiesPanel/PropertyControls/ValidationEditor/ValidationDrawer.svelte +++ b/packages/builder/src/components/design/PropertiesPanel/PropertyControls/ValidationEditor/ValidationDrawer.svelte @@ -9,13 +9,13 @@ Body, Input, DatePicker, - Multiselect, } 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" + import Multiselect from "../../../../../../../bbui/src/Form/Core/Multiselect.svelte" export let rules = [] export let bindings = [] @@ -58,14 +58,22 @@ label: "Must not match regex", value: "notRegex", }, - Contains: { + ContainsRowID: { label: "Must contain row ID", value: "contains", }, - NotContains: { + NotContainsRowID: { label: "Must not contain row ID", value: "notContains", }, + Contains: { + label: "Must contain one of", + value: "contains", + }, + NotContains: { + label: "Must not contain one of", + value: "notContains", + }, } const ConstraintMap = { ["string"]: [ @@ -98,8 +106,8 @@ ["attachment"]: [Constraints.Required], ["link"]: [ Constraints.Required, - Constraints.Contains, - Constraints.NotContains, + Constraints.ContainsRowID, + Constraints.NotContainsRowID, Constraints.MinLength, Constraints.MaxLength, ], @@ -107,6 +115,8 @@ Constraints.Required, Constraints.MinLength, Constraints.MaxLength, + Constraints.Contains, + Constraints.NotContains, ], } @@ -195,6 +205,7 @@ valueType: "Binding", type: fieldType, id: generate(), + value: fieldType == "array" ? [] : null, }, ] } @@ -280,7 +291,7 @@ disabled={rule.constraint === "required"} on:change={e => (rule.value = e.detail)} /> - {:else if ["maxLength", "minLength", "regex", "notRegex", "contains", "notContains"].includes(rule.constraint)} + {:else if ["maxLength", "minLength", "regex", "notRegex", "containsRowID", "notContainsRowID"].includes(rule.constraint)} {:else} - {#if ["string", "number", "options", "longform", "array"].includes(rule.type)} + {#if ["string", "number", "options", "longform"].includes(rule.type)} + {:else if rule.type === "array" && ["contains", "notContains"].includes(rule.constraint)} + x} + getOptionValue={x => x} + on:change={e => (rule.value = e.detail)} + bind:value={rule.value} + /> {:else if rule.type === "boolean"}