diff --git a/app/form/utils.test.ts b/app/form/utils.test.ts index e490acd6b..056681347 100644 --- a/app/form/utils.test.ts +++ b/app/form/utils.test.ts @@ -1,7 +1,13 @@ import * as v from "valibot"; import { describe, expect, test } from "vitest"; import { preprocess } from "~/utils/schema"; -import { getNestedSchema, getNestedValue, setNestedValue } from "./utils"; +import { array, textField } from "./fields"; +import { + getNestedSchema, + getNestedValue, + setNestedValue, + validateField, +} from "./utils"; describe("getNestedValue", () => { test("returns value at simple path", () => { @@ -156,3 +162,27 @@ describe("getNestedSchema", () => { expect(result?.type).toBe("string"); }); }); + +describe("validateField", () => { + const linksSchema = v.object({ + links: array({ + label: "labels.urls", + max: 10, + field: textField({ maxLength: 150, validate: "url" }), + }), + }); + + test.each([ + { + why: "invalid url", + value: "twitter.com/me", + expected: "forms:errors.invalidUrl", + }, + { why: "empty", value: "", expected: "forms:errors.required" }, + ])( + "validates a row of a list of plain values ($why)", + ({ value, expected }) => { + expect(validateField(linksSchema, "links[0]", value)).toBe(expected); + }, + ); +}); diff --git a/app/form/utils.ts b/app/form/utils.ts index 1a2bbf86d..cddbcdbdb 100644 --- a/app/form/utils.ts +++ b/app/form/utils.ts @@ -208,9 +208,7 @@ export function validateField( name: string, value: unknown, ): string | undefined { - const fieldSchema = name.includes(".") - ? getNestedSchema(schema, name) - : (schema.entries[name] as AnySyncSchema | undefined); + const fieldSchema = getNestedSchema(schema, name); if (!fieldSchema) return undefined; const result = v.safeParse(fieldSchema, value); diff --git a/changelog/2026-10-20-list-field-validation.md b/changelog/2026-10-20-list-field-validation.md new file mode 100644 index 000000000..c9c41c610 --- /dev/null +++ b/changelog/2026-10-20-list-field-validation.md @@ -0,0 +1,5 @@ +--- +navItem: [u, art] +type: bug +--- +Fix invalid links on the links widget showing no error and Save silently doing nothing, and unclear errors for empty linked user rows on art