From 106b7b9ebd3c86d1b8a41076b479bb7b47468241 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Fri, 16 Apr 2021 11:32:41 +0100 Subject: [PATCH] Use BBUI checkbox in standard components --- packages/bbui/src/Form/Core/index.js | 2 +- .../src/forms/BooleanField.svelte | 45 ++++--------------- .../src/forms/RelationshipField.svelte | 11 ++++- 3 files changed, 19 insertions(+), 39 deletions(-) diff --git a/packages/bbui/src/Form/Core/index.js b/packages/bbui/src/Form/Core/index.js index 8c309eca85..b8af2ca9e1 100644 --- a/packages/bbui/src/Form/Core/index.js +++ b/packages/bbui/src/Form/Core/index.js @@ -1,4 +1,4 @@ export { default as CoreTextField } from "./TextField.svelte" export { default as CoreSelect } from "./Select.svelte" export { default as CoreMultiselect } from "./Multiselect.svelte" -export { default as Checkbox } from "./Checkbox.svelte" +export { default as CoreCheckbox } from "./Checkbox.svelte" diff --git a/packages/standard-components/src/forms/BooleanField.svelte b/packages/standard-components/src/forms/BooleanField.svelte index 6e38c22be4..26db4aa96d 100644 --- a/packages/standard-components/src/forms/BooleanField.svelte +++ b/packages/standard-components/src/forms/BooleanField.svelte @@ -1,5 +1,5 @@ {#if fieldState} -
- -
+ fieldApi.setValue(e.detail)} + {text} /> {/if}
- - diff --git a/packages/standard-components/src/forms/RelationshipField.svelte b/packages/standard-components/src/forms/RelationshipField.svelte index 3e7ef7b0e6..85643be227 100644 --- a/packages/standard-components/src/forms/RelationshipField.svelte +++ b/packages/standard-components/src/forms/RelationshipField.svelte @@ -21,6 +21,8 @@ $: linkedTableId = fieldSchema?.tableId $: fetchRows(linkedTableId) $: fetchTable(linkedTableId) + $: singleValue = flatten($fieldState?.value)?.[0] + $: multiValue = flatten($fieldState?.value) ?? [] const fetchTable = async id => { if (id) { @@ -38,6 +40,13 @@ } } + const flatten = values => { + if (!values) { + return [] + } + return values.map(value => (typeof value === "object" ? value._id : value)) + } + const getDisplayName = row => { return row?.[tableDefinition?.primaryDisplay || "_id"] || "-" } @@ -64,7 +73,7 @@