gcanti / tcomb-form

Forms library for react
https://gcanti.github.io/tcomb-form
MIT License
1.16k stars 136 forks source link

Factory for a list of structs #227

Closed nerdstep closed 8 years ago

nerdstep commented 8 years ago

Trying to wrap my head around the best way to go about the following scenario, and was wondering if anyone had any suggestions...

Given this form setup:

var FormType = t.struct({
  a: t.list(t.struct({
    b: t.Str,
    c: t.list(t.enum({})),
    d: t.enum({})
  })
});

So essentially, I have a field which is a list of structs with further nested lists and other types, and what I'm trying to do is provide a custom component to render the "a" field list, as well as a custom component for the "c" list, but use the native component templates for "b" and "d". For example, my primary "a" field component is going to be a form which returns the values from its b,c, & d inputs. I might render this is a modal for instance. Part of my problem is that I have multiple fields which are lists of structs with various field types, and the default list rendering is too bulky, especially once you start nesting lists.

Conceptually I'm having a hard time trying to figure out how to create a factory to deal with this. Can I iterate over each type in the list and make a determination to use the native template or my custom component? Or am I better off just creating a factory that renders each list of fields according to what I know the inputs types are going to be? Which seems like an ugly way of doing things.

Appreciate anyone's thoughts or suggestions. Cheers.

nerdstep commented 8 years ago

Going to close this. Basically solved this by creating a custom factory that renders custom input components with some type information passed in via the field options. It gets the job done anyway.