From 335fd05ba55ec43470b99e21faf01d3a886c487b Mon Sep 17 00:00:00 2001 From: dararod Date: Wed, 13 Mar 2024 12:02:19 -0400 Subject: [PATCH 1/3] feat: implement validate options --- src/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index 6f6109c..2ad52b1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,7 +4,7 @@ import { isSchema, ValidationError } from 'yup'; import { clone } from './utils'; import type { Readable, Unsubscriber, Writable } from 'svelte/store'; -import type { Schema } from 'yup'; +import type { Schema, ValidateOptions } from 'yup'; export { field } from './action'; @@ -249,6 +249,8 @@ export type FormConfig = { * [1]: https://github.com/jquense/yup */ validationSchema?: Schema; + + validationOption?: ValidateOptions; }; /** @@ -516,9 +518,7 @@ export const newForm: NewFormFn = ( try { __isValidating.set(true); - await config.validationSchema.validate(currentValues, { - abortEarly: false, - }); + await config.validationSchema.validate(currentValues, config.validationOption); } catch (error) { console.warn(error); if (error?.inner) { From 63d1667a32cd597c89cbdbe823d7994d44adb230 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Wed, 13 Mar 2024 18:29:12 -0400 Subject: [PATCH 2/3] Update src/index.ts Co-authored-by: Esteban Borai --- src/index.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 2ad52b1..28aab76 100644 --- a/src/index.ts +++ b/src/index.ts @@ -249,8 +249,12 @@ export type FormConfig = { * [1]: https://github.com/jquense/yup */ validationSchema?: Schema; - - validationOption?: ValidateOptions; + /** + * [Yup][1] validation options used internally + * + * [1]: https://github.com/jquense/yup + */ + validationOptions?: ValidateOptions; }; /** From 85c6242c7eaa69a2549b943160c6019b788e0a22 Mon Sep 17 00:00:00 2001 From: dararod Date: Wed, 13 Mar 2024 18:32:39 -0400 Subject: [PATCH 3/3] fix: set aboutEarly false --- src/index.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 28aab76..022d7fa 100644 --- a/src/index.ts +++ b/src/index.ts @@ -522,7 +522,12 @@ export const newForm: NewFormFn = ( try { __isValidating.set(true); - await config.validationSchema.validate(currentValues, config.validationOption); + await config.validationSchema.validate( + currentValues, + config.validationOptions + ? config.validationOptions + : { abortEarly: false }, + ); } catch (error) { console.warn(error); if (error?.inner) {