Skip to content

Commit

Permalink
Merge pull request #173 from gcanti/80
Browse files Browse the repository at this point in the history
add support for lists, ref #80
  • Loading branch information
gcanti authored Jul 8, 2016
2 parents dc9ec55 + 5ba6819 commit de3d306
Show file tree
Hide file tree
Showing 9 changed files with 665 additions and 119 deletions.
89 changes: 89 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,95 @@ var options = {

This will completely skip the rendering of the component, while the default value will be available for validation purposes.

# Lists

You can handle a list with the `t.list` combinator:

```js
const Person = t.struct({
name: t.String,
tags: t.list(t.String) // a list of strings
});
```

## Items configuration

To configure all the items in a list, set the `item` option:

```js
const Person = t.struct({
name: t.String,
tags: t.list(t.String) // a list of strings
});

const options = {
fields: { // <= Person options
tags: {
item: { // <= options applied to each item in the list
label: 'My tag'
}
}
}
});
```

## Nested structures

You can nest lists and structs at an arbitrary level:

```js
const Person = t.struct({
name: t.String,
surname: t.String
});

const Persons = t.list(Person);
```

# Managing unions

**Example**

```js
const AccountType = t.enums.of([
'type 1',
'type 2',
'other'
], 'AccountType')

const KnownAccount = t.struct({
type: AccountType
}, 'KnownAccount')

const UnknownAccount = t.struct({
type: AccountType,
label: t.String
}, 'UnknownAccount')

// the union type
const Account = t.union([KnownAccount, UnknownAccount], 'Account')

// you must define a dispatch function returning the suitable type
// based on the current form value
Account.dispatch = value => {
return value && value.type === 'other' ? UnknownAccount : KnownAccount
}

const Type = Account

// options can be a list of options, one for each type of the union
const options = [
// options of the KnownAccount type
{
label: 'KnownAccount'
},
// options of theUnknownAccount type
{
label: 'UnknownAccount'
}
]
```

# Customizations

## Stylesheets
Expand Down
Loading

0 comments on commit de3d306

Please sign in to comment.