gcanti / tcomb-form

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

Nested structures and adding not new, but already existing items #400

Open hetsch opened 6 years ago

hetsch commented 6 years ago

Version

Tell us which versions you are using:

Using these structures:

const Actor = t.struct({
    name: t.Str
});

const Movie = t.struct({
    name: t.Str,
    actors: Actor
});

Right now if I have nested structures, the library provides an add button to dynamically attach new items, in this case Actor(s), to the nested list structure. This is as easy as it could be.

Now think about the situation if I don't want to add a new actor to the list, but instead want to add an already existing actor that might be populated from a database. In this case it would be awesome if one could append an actor structure by clicking a choose button and selecting an preexisting actor from a select box and dynamically adding the chosen actor to the list of actors within the movie.

I don't exactly know what would be a sane way to implement such a choose button. I think that I have to change the template to add the choose button and the actor select box with the actors populated from the db. Once one was chosen, I think I need to update the form state.

I have read the source code of this library and found the addItem function that handles the case of adding new items, but I cannot image who to handle the case of preexisting items. Any help or a small example would help me tremendously. (By the way, thank you for this wonderful library!!)