diff --git a/apps/tailwind-components/components/form/FieldInput.vue b/apps/tailwind-components/components/form/FieldInput.vue index b15b55b1b6..0ae28a15cd 100644 --- a/apps/tailwind-components/components/form/FieldInput.vue +++ b/apps/tailwind-components/components/form/FieldInput.vue @@ -51,7 +51,7 @@ function validate(value: columnValue) { @focus="$emit('focus')" @update:modelValue="$emit('update:modelValue', $event)" @error="$emit('error', $event)" - > + /> + /> + diff --git a/apps/tailwind-components/components/input/Hyperlink.vue b/apps/tailwind-components/components/input/Hyperlink.vue new file mode 100644 index 0000000000..69af5711d9 --- /dev/null +++ b/apps/tailwind-components/components/input/Hyperlink.vue @@ -0,0 +1,61 @@ + + + + + diff --git a/apps/tailwind-components/components/input/String.vue b/apps/tailwind-components/components/input/String.vue index 2d3e2291c9..4e61af7694 100644 --- a/apps/tailwind-components/components/input/String.vue +++ b/apps/tailwind-components/components/input/String.vue @@ -25,11 +25,14 @@ defineExpose({ validate }); function validate(value: columnValue) { if (props.required && value === "") { - emit("error", [ + const errors = [ { message: `${props.label || props.id} required to complete the form` }, - ]); + ]; + emit("error", errors); + return errors; } else { emit("error", []); + return []; } } diff --git a/apps/tailwind-components/pages/Form.story.vue b/apps/tailwind-components/pages/Form.story.vue index 38410566c5..1453c6dbef 100644 --- a/apps/tailwind-components/pages/Form.story.vue +++ b/apps/tailwind-components/pages/Form.story.vue @@ -41,7 +41,6 @@ const formFields = ref>(); const formValues = ref>({}); function onModelUpdate(value: Record) { - console.log("story update", value); formValues.value = value; } diff --git a/apps/tailwind-components/pages/input/Hyperlink.story.vue b/apps/tailwind-components/pages/input/Hyperlink.story.vue new file mode 100644 index 0000000000..0736616897 --- /dev/null +++ b/apps/tailwind-components/pages/input/Hyperlink.story.vue @@ -0,0 +1,41 @@ + + Hyperlink component + + The Hyperlink Component enables you to use the String component + with the added validation of the input being a hyperlink. + + + + + Input Hyperlink: (model value: {{ demoValue }}) + + {{ label }} + + + Error: {{ error[0]?.message }} + + + + + diff --git a/apps/tailwind-components/tests/components/form/inputHyperlink.spec.ts b/apps/tailwind-components/tests/components/form/inputHyperlink.spec.ts new file mode 100644 index 0000000000..654033f000 --- /dev/null +++ b/apps/tailwind-components/tests/components/form/inputHyperlink.spec.ts @@ -0,0 +1,27 @@ +import { expect, test } from "@playwright/test"; +import playwrightConfig from "../../../playwright.config"; +const route = playwrightConfig?.use?.baseURL?.startsWith("http://localhost") + ? "" + : "/apps/tailwind-components/#/"; + +test.beforeEach(async ({ page }) => { + await page.goto(`${route}input/Hyperlink.story`); + await page + .getByRole("textbox", { name: "Input a hyperlink" }) + .click({ delay: 500 }); +}); + +test("the inputHyperLink", async ({ page }) => { + await expect(page.getByText("Error:")).not.toContainText( + "Error: Invalid hyperlink" + ); + await page.fill("#input-hyperlink", "blaat"); + await expect(page.getByText("Error: Invalid hyperlink")).toContainText( + "Error: Invalid hyperlink" + ); + await page.getByPlaceholder("https://example.com").clear(); + await page.fill("#input-hyperlink", "https://molgenis.net"); + await expect(page.getByText("Error:")).not.toContainText( + "Error: Invalid hyperlink" + ); +});
+ The Hyperlink Component enables you to use the String component + with the added validation of the input being a hyperlink. +
Hyperlink Component