gcanti / tcomb-form

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

Options for (child) properties in object? #296

Closed emiloberg closed 8 years ago

emiloberg commented 8 years ago

Hi,

I've a JSON Schema (transformed by tcomb-json-schema which looks a bit like this:

{
  "schema": {
    "type": "object",
    "properties": {
      "anObject": {
        "type": "object",
        "properties": {
          "aBool": { "type": "boolean" },
          "aString": { "type": "string" }
        }
      }
    }
  }
}

Is there any way I can reach the firstBool and secondBool in my options, e.g. an options object looking a bit like this:

{
  options: {
    fields: {
      anObject: {
        properties: {
          aBool: { label: 'hi' },
          aString: { help: 'This is a string' }
        }
      }
    }
  }
}
gcanti commented 8 years ago

Yep. Just replace properties with fields:

options: {
  fields: {
    anObject: {
      fields: { // <= here
        aBool: { label: 'hi' },
        aString: { help: 'This is a string' }
      }
    }
  }
}
emiloberg commented 8 years ago

Gaah! Could have sworn that I tried that, but I guess I missed it amongst field, properties, props and the rest of the list ;)

Cheers!

sagannotcarl commented 8 years ago

In case anyone else finds this I was having a problem getting this to work. If you have a field that is a type t.list() that uses another type with multiple fields. It needs to be nested inside an item element.

The above example should be changed to:

options: {
  fields: {
    anObject: {
      item: {
        fields: {
          aBool: { label: 'hi' },
          aString: { help: 'This is a string' }
        }
      }
    }
  }
}