gcanti / tcomb-form

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

How to pass options for sub-schema's #279

Closed Industrial closed 8 years ago

Industrial commented 8 years ago

Hi.

In my case I have a resume form with;

const ExperienceSchema = tcombForm.struct({
  companyName: tcombForm.String,
  title: tcombForm.String,
  location: tcombForm.String,
  startDate: tcombForm.Date,
  endDate: tcombForm.Date,

  // TODO: Textarea input
  shortDescription: tcombForm.String,

  // TODO: Tag text input
  technologies: tcombForm.list(tcombForm.String),
  methodologies: tcombForm.list(tcombForm.String)
});

const EmployeeSchema = tcombForm.struct({
  name: tcombForm.String,
  surname: tcombForm.String,

  email: tcombFormTypes.String.Email,
  phonenumber: tcombForm.String,

  github: tcombForm.maybe(tcombForm.String),
  linkedin: tcombForm.maybe(tcombForm.String),

  dateOfBirth: tcombForm.Date,
  nationality: tcombForm.enums(nationalitiesObject),

  education: tcombForm.list(EducationSchema),
  courses: tcombForm.list(CoursesSchema),
  experience: tcombForm.list(ExperienceSchema)
});

How do I pass options to the <Form options={{x: y}}> that allow me to customize fields in a sub-schema?

Right now the options { fields: { experience: { shortDescription: { type: 'text' } } } } doesn't seem to do it.

Thanks!

gcanti commented 8 years ago

Hi, You can use the fields option for structs and the item option for lists, at arbitrary levels of nesting

const options = {
  fields: { // first level of nesting (EmployeeSchema struct)
    experience: {
      item: { // second level of nesting (list of ExperienceSchemas)
        fields: { // third level of nesting (ExperienceSchema struct)
          shortDescription: {
            type: 'textarea' // Textarea input
          }
        }
      }
    }
  }
}
Industrial commented 8 years ago

Aaah sorry, I must have misread. Thanks!