Effect CommunityEC
Effect Community2y ago
41 replies
Nanniiii

Assigning Error Messages to Specific Inputs in Effect/Schema with Hook Resolvers

Hello, i didn't find it in the readme, i'm using effect/schema with hook resolvers.

and i want to assign an error msg in a filter to a specific input.

i need access to an other field so the filter is on the Struct one level above.

address: S.Struct({
        streetNumber: OptionalString,
        streetName: ValidString,
        additionalAddressInformation: OptionalString,
        country: CountryCodes,
        postalCode: ValidString.annotations({ identifier: "postalCode" }),
        city: ValidString,
    }).pipe(
        S.filter(
            (address) => {
                if (!getPostalCodeSchema(address.country).safeParse(address.postalCode).success)
                    return getKey("app.settings.edit-personal-information", "ERROR_POSTAL_CODE")
                return true
            },
            { identifier: "postalCode" },
        ),
    ),


i can't find a way to associate the error msg to postalCode fields so react-hook-resolver will associate the error to it and not address.root
Was this page helpful?