diff --git a/packages/fieldy/fieldy-react/src/components/Field/index.tsx b/packages/fieldy/fieldy-react/src/components/Field/index.tsx index 2bbb602e7..ff3993db7 100644 --- a/packages/fieldy/fieldy-react/src/components/Field/index.tsx +++ b/packages/fieldy/fieldy-react/src/components/Field/index.tsx @@ -18,8 +18,7 @@ export const Field = ( } ) => { const { name, value, initialValue, defaultValue, children, type, rules } = props - const fieldMeta = useCreateFieldSchema(name, type) - fieldMeta.validateRules = rules + const fieldMeta = useCreateFieldSchema(name, type, rules) return ( diff --git a/packages/fieldy/fieldy-react/src/components/XField/hooks/useCreateFieldSchema.ts b/packages/fieldy/fieldy-react/src/components/XField/hooks/useCreateFieldSchema.ts index 25092ffcd..052b6e249 100644 --- a/packages/fieldy/fieldy-react/src/components/XField/hooks/useCreateFieldSchema.ts +++ b/packages/fieldy/fieldy-react/src/components/XField/hooks/useCreateFieldSchema.ts @@ -2,8 +2,9 @@ import { IFieldSchema } from "@rxdrag/fieldy" import { useMemo, useRef } from "react" import { useFieldPath } from "../../../hooks/useFieldPath" import { FieldType } from "@rxdrag/fieldy" +import { IYupValidateSchema } from "@rxdrag/fieldy-yup-validation" -export function useCreateFieldSchema(name: string | number, type?: FieldType) { +export function useCreateFieldSchema(name: string | number, type?: FieldType, rules?: IYupValidateSchema) { const parentPath = useFieldPath() || "" const fieldPath = useMemo(() => { return parentPath ? parentPath + "." + name : name.toString() @@ -15,9 +16,10 @@ export function useCreateFieldSchema(name: string | number, type?: FieldType) { return { path: fieldPath, type: type, - name + name, + validateRules: rules, } - }, [fieldPath, name, type]) + }, [fieldPath, name, rules, type]) return fieldSchema } \ No newline at end of file diff --git a/packages/fieldy/fieldy/src/classes/FormImpl.ts b/packages/fieldy/fieldy/src/classes/FormImpl.ts index 562566333..62cd8fd4a 100644 --- a/packages/fieldy/fieldy/src/classes/FormImpl.ts +++ b/packages/fieldy/fieldy/src/classes/FormImpl.ts @@ -113,6 +113,7 @@ export class FormImpl implements IForm { try { const value = await this.fieldy.validator.validateForm(this) + this.validationSubscriber.emitSuccess(value) return { status: ValidateStatus.success, diff --git a/packages/fieldy/yup-validation/src/classes/YupValidator.ts b/packages/fieldy/yup-validation/src/classes/YupValidator.ts index ec56de099..1ad1c9d15 100644 --- a/packages/fieldy/yup-validation/src/classes/YupValidator.ts +++ b/packages/fieldy/yup-validation/src/classes/YupValidator.ts @@ -1,6 +1,6 @@ import { IField, IFieldSchema, IForm, IValidationError, IValidator } from "@rxdrag/fieldy"; import { PredeinedValidators, YupType, IYupValidateSchema } from "../interfaces"; -import { object, string, boolean, number, ValidationError, Schema, mixed } from 'yup'; +import { object, ValidationError, Schema, mixed } from 'yup'; import { predifinedValidators } from "../predefineds"; export class YupValidator implements IValidator { @@ -17,8 +17,7 @@ export class YupValidator implements IValidator { this.validateOneObject(field?.getValue(), field?.getSubFieldSchemas() || []) } } - const rootSchemas = form.getRootFields() - return this.validateOneObject(form.getValue(), rootSchemas) + return this.validateOneObject(form.getValue(), schemas) } validateField(field: IField): Promise {