gcanti / tcomb-form

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

How to implmenet something like Rails' collection_checkboxes #347

Closed motro closed 8 years ago

motro commented 8 years ago

I'd like to create a form that holds both a Person's fields (first name, last name, etc') and a checkboxes list of the selected hobbies, just like Rails' collection_check_boxes (http://apidock.com/rails/v4.0.2/ActionView/Helpers/FormOptionsHelper/collection_check_boxes)

The hobbies come from a different data source so their number may vary.

How would you recommend implementing that?

Thanks!

gcanti commented 8 years ago

Something along the lines of

const hobbies = ['surf', 'tennis']

const hobbiesProps = {}

hobbies.forEach(h => hobbiesProps[h] = t.Boolean)

const Type = t.struct({
  firstName: t.String,
  lastName: t.String,
  hobbies: t.struct(hobbiesProps)
})
motro commented 8 years ago

Thanks for the super-fast response! I'll try this one and let you know.