Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

field paths lost with lazy and dynamic keys #2257

Open
franck102 opened this issue Nov 27, 2024 · 0 comments
Open

field paths lost with lazy and dynamic keys #2257

franck102 opened this issue Nov 27, 2024 · 0 comments

Comments

@franck102
Copy link

franck102 commented Nov 27, 2024

I am trying to validate a Record<number, Settings> where the keys are dynamically retrieved from an API.

I have this schema:

const formSchema = object({
venueSettings: lazy((value: Record<number, Settings>) => {
    let schema = object();
    for (const venue of venues.value) {
      var s = value?.[venue.id];
      if (s != null && (s.userId || s.spaceId || s.apiSecret)) {
        schema = schema.shape({
          [venue.id]: object().label(venue.id).shape({
            userId: string().required("Veuillez entrer votre identifiant d'utilisateur"),
            spaceId: string().required("Veuillez entrer votre identifiant de Space"),
            apiSecret: string().required("Veuillez entrer votre clé d'API")
          })
        })
      }
    }
    console.log("Schema: " + JSON.stringify(schema,  null,  2));
    return schema;
  })
});

which does catch errors, however the path stops at venueSettings:
Form errors: {"venueSettings":"Veuillez entrer votre identifiant d'utilisateur"}

How can I get the error reported under venueSettings.4.userId ?

I created what I believe is a reproducible example, though I can't figure out how to actually run the test in codesandbox :(

Codesandbox test case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant