fabian-hiller / modular-forms

The modular and type-safe form library for SolidJS, Qwik and Preact
https://modularforms.dev
MIT License
1.05k stars 55 forks source link

Is it possible to create a form with recursive field? #251

Open mattp0123 opened 1 month ago

mattp0123 commented 1 month ago

i have a form like this:

type Condition =
  | {
      type: 'composite'
      operator: 'and' | 'or'
      conditions: Condition[]
    }
  | OtherCondition

type Form = {
  condition: Condition
}

seems a bit like nested & array field approach. could have dynamic field path like:

<Field name={`condition.conditions.${index}.type`} />

but i got this error when i trying to create the form:

image

fabian-hiller commented 1 month ago

Hmm... the recursive type probably breaks the types of the library. 😐

mattp0123 commented 1 month ago

@fabian-hiller maybe this could help: https://dev.to/scooperdev/supporting-circularly-referenced-mapped-types-in-typescript-4825

fabian-hiller commented 1 month ago

Yes, this might work, but it limits the depth. You can do this yourself by explicitly specifying a depth of only 10 instead of infinity in your schema.