From 4c94f85aed717d32691bde7541ae7e48132b1ce1 Mon Sep 17 00:00:00 2001 From: eyelidlessness Date: Mon, 13 Jan 2025 15:24:30 -0800 Subject: [PATCH] web-forms (Vue UI): integrate value type suport for selects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Note that this doesn’t _currently_ do anything special for individual value types! I think that’s expected for the subset of value types we presently implement (which are all represented as primitive values, and all presentable in the current UI controls the same way string values have been). That will necessarily change as we add support for more complex value type representations (e.g. geo). --- .../src/fixtures/select/5-select-types.xml | 187 ++++++++++++++++++ .../web-forms/src/components/FormQuestion.vue | 4 +- .../components/controls/Select1Control.vue | 8 +- .../src/components/controls/SelectControl.vue | 8 +- .../components/controls/SelectNControl.vue | 8 +- .../src/components/widgets/CheckboxWidget.vue | 23 ++- .../src/components/widgets/LikertWidget.vue | 8 +- .../widgets/MultiselectDropdown.vue | 16 +- .../src/components/widgets/RadioButton.vue | 21 +- .../components/widgets/SearchableDropdown.vue | 16 +- .../src/lib/format/selectOptionId.ts | 5 + .../tests/components/FormQuestion.test.ts | 4 +- .../tests/components/SelectControl.test.ts | 23 ++- 13 files changed, 268 insertions(+), 63 deletions(-) create mode 100644 packages/common/src/fixtures/select/5-select-types.xml create mode 100644 packages/web-forms/src/lib/format/selectOptionId.ts diff --git a/packages/common/src/fixtures/select/5-select-types.xml b/packages/common/src/fixtures/select/5-select-types.xml new file mode 100644 index 000000000..ec005d468 --- /dev/null +++ b/packages/common/src/fixtures/select/5-select-types.xml @@ -0,0 +1,187 @@ + + + + Select types + + + + yes + + + explicit string + implicit string + 123 + 45.67 + + + + explicit string + implicit string + 123 + 45.67 + + + + + + + + implicit string + + + + explicit string + + + + updated string + + + + + + implicit + + + + explicit + + + + updated + + + + string + + + + + + + + 123 + + + + 10 + + + + 23 + + + + 89 + + + + + + + + 45.67 + + + + 89 + + + + 10 + + + + 23.4 + + + + + + + + + + + + + + + + + + + + yes + + + + no + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/web-forms/src/components/FormQuestion.vue b/packages/web-forms/src/components/FormQuestion.vue index d5bf0519f..d8ea43bc5 100644 --- a/packages/web-forms/src/components/FormQuestion.vue +++ b/packages/web-forms/src/components/FormQuestion.vue @@ -3,8 +3,8 @@ import type { AnyControlNode, AnyInputNode, AnyNoteNode, + AnySelectNode, AnyUnsupportedControlNode, - SelectNode, } from '@getodk/xforms-engine'; import { inject } from 'vue'; import InputControl from './controls/Input/InputControl.vue'; @@ -19,7 +19,7 @@ type ControlNode = AnyControlNode | AnyUnsupportedControlNode; defineProps<{ question: ControlNode }>(); const isInputNode = (node: ControlNode): node is AnyInputNode => node.nodeType === 'input'; -const isSelectNode = (node: ControlNode): node is SelectNode => node.nodeType === 'select'; +const isSelectNode = (node: ControlNode): node is AnySelectNode => node.nodeType === 'select'; const isNoteNode = (node: ControlNode): node is AnyNoteNode => node.nodeType === 'note'; const isRangeNode = (node: ControlNode) => node.nodeType === 'range'; const isTriggerNode = (node: ControlNode) => node.nodeType === 'trigger'; diff --git a/packages/web-forms/src/components/controls/Select1Control.vue b/packages/web-forms/src/components/controls/Select1Control.vue index 3aaba66b3..15d58abf1 100644 --- a/packages/web-forms/src/components/controls/Select1Control.vue +++ b/packages/web-forms/src/components/controls/Select1Control.vue @@ -1,5 +1,5 @@