From 5b40ef242264841073af1188f41c235d46241793 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Fri, 14 Jan 2022 09:58:23 +0000 Subject: [PATCH 1/7] Fix issue where error was always reset when a component was re-registered --- .../src/components/app/forms/InnerForm.svelte | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/packages/client/src/components/app/forms/InnerForm.svelte b/packages/client/src/components/app/forms/InnerForm.svelte index 47bc717d92..6c51a85f19 100644 --- a/packages/client/src/components/app/forms/InnerForm.svelte +++ b/packages/client/src/components/app/forms/InnerForm.svelte @@ -141,8 +141,18 @@ return } + // Create validation function based on field schema + const schemaConstraints = schema?.[field]?.constraints + const validator = createValidatorFromConstraints( + schemaConstraints, + validationRules, + field, + table + ) + // If we've already registered this field then keep some existing state let initialValue = deepGet(initialValues, field) ?? defaultValue + let initialError = null let fieldId = `id-${generateID()}` const existingField = getField(field) if (existingField) { @@ -156,20 +166,17 @@ } else { initialValue = fieldState.value ?? initialValue } + + // If this field has already been registered and we previously had an + // error set, then re-run the validator to see if we can unset it + if (fieldState.error) { + initialError = validator(initialValue) + } } // Auto columns are always disabled const isAutoColumn = !!schema?.[field]?.autocolumn - // Create validation function based on field schema - const schemaConstraints = schema?.[field]?.constraints - const validator = createValidatorFromConstraints( - schemaConstraints, - validationRules, - field, - table - ) - // Construct field info const fieldInfo = writable({ name: field, @@ -178,7 +185,7 @@ fieldState: { fieldId, value: initialValue, - error: null, + error: initialError, disabled: disabled || fieldDisabled || isAutoColumn, defaultValue, validator, @@ -254,6 +261,7 @@ // Update field state const error = validator ? validator(value) : null + console.log("value changed to", value, "new error is", error) fieldInfo.update(state => { state.fieldState.value = value state.fieldState.error = error From 283c4a5d9fd23e5ff900dea28cc2c961dee690dc Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Fri, 14 Jan 2022 16:47:50 +0000 Subject: [PATCH 2/7] Remove log --- packages/client/src/components/app/forms/InnerForm.svelte | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/client/src/components/app/forms/InnerForm.svelte b/packages/client/src/components/app/forms/InnerForm.svelte index 6c51a85f19..c1e92bf442 100644 --- a/packages/client/src/components/app/forms/InnerForm.svelte +++ b/packages/client/src/components/app/forms/InnerForm.svelte @@ -261,7 +261,6 @@ // Update field state const error = validator ? validator(value) : null - console.log("value changed to", value, "new error is", error) fieldInfo.update(state => { state.fieldState.value = value state.fieldState.error = error From d2ffc2e920ebe2909f25fe7c737544bac736f40a Mon Sep 17 00:00:00 2001 From: Bastiaan Terhorst Date: Tue, 18 Jan 2022 15:04:40 +0100 Subject: [PATCH 3/7] Update MultiFieldSelect to accept a defaultValue This changes the multi select control to accept defaultValues. As these are passed in as strings (flattened arrays in the form of "1, 2, 3") they need to be split into an array to be accepted by the control. --- .../components/app/forms/MultiFieldSelect.svelte | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/client/src/components/app/forms/MultiFieldSelect.svelte b/packages/client/src/components/app/forms/MultiFieldSelect.svelte index cecc569b6f..06811f3e05 100644 --- a/packages/client/src/components/app/forms/MultiFieldSelect.svelte +++ b/packages/client/src/components/app/forms/MultiFieldSelect.svelte @@ -20,6 +20,7 @@ let fieldSchema $: flatOptions = optionsSource == null || optionsSource === "schema" + $: expandedValue = expand(fieldState?.value) $: options = getOptions( optionsSource, fieldSchema, @@ -28,6 +29,18 @@ valueColumn, customOptions ) + + const expand = values => { + if (!values) { + return [] + } + + if (Array.isArray(values)) { + return values + } + + return values.split(",") + } {#if fieldState} x : x => x.label} getOptionValue={flatOptions ? x => x : x => x.value} From 7ed18caa31ffc790789b045e9559e8ae0efd3aec Mon Sep 17 00:00:00 2001 From: Bastiaan Terhorst Date: Tue, 18 Jan 2022 16:48:08 +0100 Subject: [PATCH 4/7] also set defaultValue --- .../client/src/components/app/forms/MultiFieldSelect.svelte | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/client/src/components/app/forms/MultiFieldSelect.svelte b/packages/client/src/components/app/forms/MultiFieldSelect.svelte index 06811f3e05..5705b28e14 100644 --- a/packages/client/src/components/app/forms/MultiFieldSelect.svelte +++ b/packages/client/src/components/app/forms/MultiFieldSelect.svelte @@ -20,6 +20,7 @@ let fieldSchema $: flatOptions = optionsSource == null || optionsSource === "schema" + $: expandedDefaultValue = expand(fieldState?.defaultValue) $: expandedValue = expand(fieldState?.value) $: options = getOptions( optionsSource, @@ -39,7 +40,7 @@ return values } - return values.split(",") + return values.split(",").map(value => value.trim()) } @@ -57,6 +58,7 @@ {#if fieldState} x : x => x.label} getOptionValue={flatOptions ? x => x : x => x.value} From a4fea9ab3c7a5323a55685068da33c65725e0395 Mon Sep 17 00:00:00 2001 From: Maurits Lourens Date: Tue, 18 Jan 2022 17:17:31 +0100 Subject: [PATCH 5/7] add extensions prop to specify accepted file extensions --- packages/bbui/src/Form/Core/Dropzone.svelte | 2 ++ packages/client/manifest.json | 7 ++++++- .../client/src/components/app/forms/AttachmentField.svelte | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/bbui/src/Form/Core/Dropzone.svelte b/packages/bbui/src/Form/Core/Dropzone.svelte index bbaf5a3ff9..f7fed78b70 100644 --- a/packages/bbui/src/Form/Core/Dropzone.svelte +++ b/packages/bbui/src/Form/Core/Dropzone.svelte @@ -22,6 +22,7 @@ export let error = null export let fileTags = [] export let maximum = null + export let extensions = "*" const dispatch = createEventDispatcher() const imageExtensions = [ @@ -207,6 +208,7 @@ {disabled} type="file" multiple + accept={extensions} on:change={handleFile} /> {/if} From 9034f23fde42cb4197156b5e871f0447a82df73c Mon Sep 17 00:00:00 2001 From: Mitch-Budibase Date: Tue, 18 Jan 2022 17:25:09 +0000 Subject: [PATCH 6/7] Small changes associated with the smoke build Removing a line from addMultiOptionDatatype Also adding a wait when creating an app - smoke build looks to have a timing issue with some tests -Just a 2 second wait for now --- .../builder/cypress/integration/addMultiOptionDatatype.spec.js | 2 +- packages/builder/cypress/support/commands.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/builder/cypress/integration/addMultiOptionDatatype.spec.js b/packages/builder/cypress/integration/addMultiOptionDatatype.spec.js index d708c7bc0b..1b67c1b3fc 100644 --- a/packages/builder/cypress/integration/addMultiOptionDatatype.spec.js +++ b/packages/builder/cypress/integration/addMultiOptionDatatype.spec.js @@ -39,4 +39,4 @@ context("Add Multi-Option Datatype", () => { }) }) }) -}) + diff --git a/packages/builder/cypress/support/commands.js b/packages/builder/cypress/support/commands.js index 666025e635..686d0ee9bf 100644 --- a/packages/builder/cypress/support/commands.js +++ b/packages/builder/cypress/support/commands.js @@ -43,6 +43,7 @@ Cypress.Commands.add("createApp", name => { } }) cy.contains(/Start from scratch/).dblclick() + cy.wait(2000) cy.get(".spectrum-Modal").within(() => { cy.get("input").eq(0).type(name).should("have.value", name).blur() cy.get(".spectrum-ButtonGroup").contains("Create app").click() From 5b58bd9be62588050b56072745e95b0f3ff380a0 Mon Sep 17 00:00:00 2001 From: Bastiaan Terhorst Date: Wed, 19 Jan 2022 09:19:49 +0100 Subject: [PATCH 7/7] set defaultValue in Field component --- .../src/components/app/forms/MultiFieldSelect.svelte | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/client/src/components/app/forms/MultiFieldSelect.svelte b/packages/client/src/components/app/forms/MultiFieldSelect.svelte index 5705b28e14..686198dfe1 100644 --- a/packages/client/src/components/app/forms/MultiFieldSelect.svelte +++ b/packages/client/src/components/app/forms/MultiFieldSelect.svelte @@ -20,8 +20,7 @@ let fieldSchema $: flatOptions = optionsSource == null || optionsSource === "schema" - $: expandedDefaultValue = expand(fieldState?.defaultValue) - $: expandedValue = expand(fieldState?.value) + $: expandedDefaultValue = expand(defaultValue) $: options = getOptions( optionsSource, fieldSchema, @@ -49,7 +48,7 @@ {label} {disabled} {validation} - {defaultValue} + defaultValue={expandedDefaultValue} type="array" bind:fieldState bind:fieldApi @@ -57,8 +56,7 @@ > {#if fieldState} x : x => x.label} getOptionValue={flatOptions ? x => x : x => x.value}