From 91a14dbe435e57415dd959a2be8ff6e961c1af5f Mon Sep 17 00:00:00 2001 From: Sandrina Pereira Date: Tue, 15 Jul 2025 09:07:58 +0100 Subject: [PATCH 1/3] chore(validation): Explain ValidationOptions --- src/validation/schema.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/validation/schema.ts b/src/validation/schema.ts index 63d7ccb04..53f2dcdcf 100644 --- a/src/validation/schema.ts +++ b/src/validation/schema.ts @@ -16,15 +16,28 @@ import { isObjectValue } from './util' export interface ValidationOptions { /** * A null value will be treated as undefined. - * That means that when validating a null value, against a non-required field that is not of type 'null' or ['null'] + * When true, providing a value to a schema that is `false`, * the validation will succeed instead of returning a type error. + * This was a bug in v0, we fixed it in v1. If you need the same behavior, set this to true. * @default false + * @example + * ```ts + * Schema: { "properties": { "name": { "type": "string" } } } + * Value: { "name": null } // Validation succeeds, even though the type is not 'null' + * ``` */ treatNullAsUndefined?: boolean - /** - * If true, providing a value for a schema that is `false` won't create an error + * A value against a schema "false" will be allowed. + * When true, providing a value to a non-required field that is not of type 'null' or ['null'] + * the validation will succeed instead of returning a type error. + * This was a bug in v0, we fixed it in v1. If you need the same behavior, set this to true. * @default false + * @example + * ```ts + * Schema: { "properties": { "age": false } } + * Value: { age: 10 } // Validation succeeds, even though the value is forbidden; + * ``` */ allowForbiddenValues?: boolean } From cb935e38a95ed42c3e24c8891a5ecaab820f5df3 Mon Sep 17 00:00:00 2001 From: Sandrina Pereira Date: Tue, 15 Jul 2025 09:08:34 +0100 Subject: [PATCH 2/3] chore(MIGRATING): Explain ValidationOptions, highlighting it's a v0 compability support --- MIGRATING.md | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/MIGRATING.md b/MIGRATING.md index 05054bab5..792ad3af2 100644 --- a/MIGRATING.md +++ b/MIGRATING.md @@ -96,8 +96,6 @@ const { formErrors } = handleValidation(values) The `modify` function API remains mostly compatible, but we removed the support for the `presentation` `errorMessage` property shorthands — `x-jsf-presentation` and `x-jsf-errorMessage` should be used instead. - - ```diff // Example: const { schema, warnings } = modify(schemaPet, { @@ -238,13 +236,44 @@ if (formErrors?.address?.street) { } ``` -### 3. **Enhanced Validation Options** +### 3. **Validation behaviors compatibility with v0** + +Some validation behaviors *were wrong* in v0, we fixed them in v1. +If you still need them, you need to enable them in the `validationOptions` option. + +Check the ValidationOptions Type for more details. + +This was a bug in v0, we fixed it in v1. If you need the same behavior, set this to true. ```typescript const form = createHeadlessForm(schema, { validationOptions: { + /** + * A null value will be treated as undefined. + * When true, providing a value to a schema that is `false`, + * the validation will succeed instead of returning a type error. + * This was a bug in v0, we fixed it in v1. If you need the same behavior, set this to true. + * @default false + * @example + * ```ts + * Schema: { "properties": { "name": { "type": "string" } } } + * Value: { "name": null } // Validation succeeds, even though the type is not 'null' + * ``` + */ + treatNullAsUndefined: true, + /** + * A value against a schema "false" will be allowed. + * When true, providing a value to a non-required field that is not of type 'null' or ['null'] + * the validation will succeed instead of returning a type error. + * This was a bug in v0, we fixed it in v1. If you need the same behavior, set this to true. + * @default false + * @example + * ```ts + * Schema: { "properties": { "age": false } } + * Value: { age: 10 } // Validation succeeds, even though the value is forbidden; + * ``` + */ allowForbiddenValues: true, - // Additional validation controls } }) ``` From bde7eb1d2169399b84bbd12217340455e3e0bc17 Mon Sep 17 00:00:00 2001 From: Sandrina Pereira Date: Tue, 15 Jul 2025 09:12:13 +0100 Subject: [PATCH 3/3] self-review --- MIGRATING.md | 36 ++++++++++++++++-------------------- src/validation/schema.ts | 4 ++-- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/MIGRATING.md b/MIGRATING.md index 792ad3af2..b8112ecb1 100644 --- a/MIGRATING.md +++ b/MIGRATING.md @@ -236,14 +236,23 @@ if (formErrors?.address?.street) { } ``` -### 3. **Validation behaviors compatibility with v0** +## Common Migration Issues + +### 1. **ESM Import Errors** -Some validation behaviors *were wrong* in v0, we fixed them in v1. -If you still need them, you need to enable them in the `validationOptions` option. +If you get import errors, ensure your project supports ESM: + +```json +// package.json +{ + "type": "module" +} +``` -Check the ValidationOptions Type for more details. +### 2. **Validation backward compatibility with v0** -This was a bug in v0, we fixed it in v1. If you need the same behavior, set this to true. +Some validation behaviors *were wrong* in `v0`, we fixed them in v1. +If you still need them, you need to enable them in the `validationOptions` config. ```typescript const form = createHeadlessForm(schema, { @@ -252,7 +261,7 @@ const form = createHeadlessForm(schema, { * A null value will be treated as undefined. * When true, providing a value to a schema that is `false`, * the validation will succeed instead of returning a type error. - * This was a bug in v0, we fixed it in v1. If you need the same behavior, set this to true. + * This was a bug in v0, we fixed it in v1. If you need the same wrong behavior, set this to true. * @default false * @example * ```ts @@ -265,7 +274,7 @@ const form = createHeadlessForm(schema, { * A value against a schema "false" will be allowed. * When true, providing a value to a non-required field that is not of type 'null' or ['null'] * the validation will succeed instead of returning a type error. - * This was a bug in v0, we fixed it in v1. If you need the same behavior, set this to true. + * This was a bug in v0, we fixed it in v1. If you need the same wrong behavior, set this to true. * @default false * @example * ```ts @@ -278,19 +287,6 @@ const form = createHeadlessForm(schema, { }) ``` -## Common Migration Issues - -### 1. **ESM Import Errors** - -If you get import errors, ensure your project supports ESM: - -```json -// package.json -{ - "type": "module" -} -``` - ## Testing Your Migration 1. **Run your test suite** to catch breaking changes diff --git a/src/validation/schema.ts b/src/validation/schema.ts index 53f2dcdcf..f3dfe9697 100644 --- a/src/validation/schema.ts +++ b/src/validation/schema.ts @@ -18,7 +18,7 @@ export interface ValidationOptions { * A null value will be treated as undefined. * When true, providing a value to a schema that is `false`, * the validation will succeed instead of returning a type error. - * This was a bug in v0, we fixed it in v1. If you need the same behavior, set this to true. + * This was a bug in v0, we fixed it in v1. If you need the same wrong behavior, set this to true. * @default false * @example * ```ts @@ -31,7 +31,7 @@ export interface ValidationOptions { * A value against a schema "false" will be allowed. * When true, providing a value to a non-required field that is not of type 'null' or ['null'] * the validation will succeed instead of returning a type error. - * This was a bug in v0, we fixed it in v1. If you need the same behavior, set this to true. + * This was a bug in v0, we fixed it in v1. If you need the same wrong behavior, set this to true. * @default false * @example * ```ts