From 7659fa808101f235157569bc08e04bd8b0f0a010 Mon Sep 17 00:00:00 2001 From: connoratrug <47183404+connoratrug@users.noreply.github.com> Date: Mon, 20 Jan 2025 09:58:27 +0100 Subject: [PATCH] feat: expose the filled out form values ( and errors) (#4612) --- .gitignore | 1 + .../components/form/Fields.vue | 25 +++-- apps/tailwind-components/pages/Form.story.vue | 100 +++++++++++++----- apps/tailwind-components/playwright.config.ts | 2 +- .../tests/components/form/renderForm.spec.ts | 6 +- 5 files changed, 93 insertions(+), 41 deletions(-) diff --git a/.gitignore b/.gitignore index a96000fd5e..a21329e050 100644 --- a/.gitignore +++ b/.gitignore @@ -68,3 +68,4 @@ requirements.txt e2e/.auth e2e/e2e/.auth e2e/test-results/ +apps/tailwind-components/test-results/.last-run.json diff --git a/apps/tailwind-components/components/form/Fields.vue b/apps/tailwind-components/components/form/Fields.vue index 2a13d79949..55fcedc568 100644 --- a/apps/tailwind-components/components/form/Fields.vue +++ b/apps/tailwind-components/components/form/Fields.vue @@ -4,6 +4,7 @@ import type { columnId, columnValue, IColumn, + IFieldError, ITableMetaData, } from "../../../metadata-utils/src/types"; @@ -12,6 +13,8 @@ const props = defineProps<{ data: Record[]; }>(); +const emit = defineEmits(["error", "update:modelValue"]); + const status = reactive({ pristine: true, touched: false, @@ -42,7 +45,7 @@ const chapters = computed(() => { }, [] as IChapter[]); }); -const dataMap = reactive( +const dataMap = reactive>( Object.fromEntries( props.metadata.columns .filter((column) => column.columnType !== "HEADING") @@ -50,7 +53,7 @@ const dataMap = reactive( ) ); -const errorMap = reactive( +const errorMap = reactive>( Object.fromEntries( props.metadata.columns .filter((column) => column.columnType !== "HEADING") @@ -83,15 +86,19 @@ function validate() { }); } +function onUpdate(column: IColumn, $event: columnValue) { + dataMap[column.id] = $event; + emit("update:modelValue", dataMap); +} +function onErrors(column: IColumn, $event: IFieldError[]) { + errorMap[column.id] = $event; + emit("error", errorMap); +} + defineExpose({ validate });