gcanti / tcomb-form

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

How to add options to nested structure? #290

Closed Joran182to closed 8 years ago

Joran182to commented 8 years ago

Hi. Let's say I have a structure like this:

const question = t.struct({
    isRequired: t.Boolean,
    questionText: t.String
});

const formStructure = t.struct({
    name: t.String,
    questions: t.list(question)
});

If i want to change 'name' s field placeholder, I do it like this in options:

const formOptions = {
    fields: {
        name: {
            attrs: {
                placeholder: 'Enter your name'
            }
        }
    }
};

But how I can set 'attrs' of nested 'questionText' field? I tried next code but it's not work:

const formOptions = {
    fields: {
        questions: {
            questionText: {
                attrs: {
                    placeholder: 'Enter your question'
                }
            }
        }
    }
};

and

const formOptions = {
    fields: {
        questionText: {
            attrs: {
                placeholder: 'Enter your question'
            }
        }
    }
};

and

const formOptions = {
    fields: {
        questions: {
            item: {
                questionText: {
                    attrs: {
                        placeholder: 'Enter your question'
                    }
                }
            }
        }
    }
};
gcanti commented 8 years ago

Hi,

There are only 2 rules:

const formOptions = {
  fields: { // struct
    name: {
      attrs: {
        placeholder: 'Enter your name'
      }
    },
    questions: {
      item: { // list
        fields: {  // struct
          questionText: {
            attrs: {
              placeholder: 'Enter your question'
            }
          }
        }
      }
    }
  }
}
gcanti commented 8 years ago

Closing for inactivity, please reopen if you need more help.