Skip to content

Commit

Permalink
feat: implement validate options (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
dararod authored Mar 13, 2024
1 parent c112e56 commit fb5f256
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -249,6 +249,12 @@ export type FormConfig<T extends object> = {
* [1]: https://github.com/jquense/yup
*/
validationSchema?: Schema;
/**
* [Yup][1] validation options used internally
*
* [1]: https://github.com/jquense/yup
*/
validationOptions?: ValidateOptions;
};

/**
Expand Down Expand Up @@ -516,9 +522,12 @@ export const newForm: NewFormFn = <T extends object>(
try {
__isValidating.set(true);

await config.validationSchema.validate(currentValues, {
abortEarly: false,
});
await config.validationSchema.validate(
currentValues,
config.validationOptions
? config.validationOptions
: { abortEarly: false },
);
} catch (error) {
console.warn(error);
if (error?.inner) {
Expand Down

0 comments on commit fb5f256

Please sign in to comment.