tcomb-form-native
tcomb-form-native copied to clipboard
Allow list values to be raw strings. Fixes #289
This fixes two separate issues, both to do with setting a custom template for a tcomb list
type.
The result is that you can use the following schema & options:
const schema = {
photos: tComb.list(tComb.String)
};
const options = {
fields: {
photos: {
// Set a custom template for the list
template: MultiPhotoTemplate
}
}
};
with the following template:
class MultiPhotoTemplate extends React.Component {
render() {
const { value } = this.props;
// Here, 'value' is an array of strings, so do what you need to do with them.
// To update the form field, call `this.props.onChange(newValue)`, where
// `newValue` is an array of strings.
}
}
@alvaromb - I was getting an error with the following code const tPosition = t.struct({ latitude: latitude, longitude: longitude }) const model = t.struct({ polygon: t.maybe(t.list(tPosition)), })
with the changes from this pull request it works as expected and my polygon is being properly validated (or at least doesn't trigger an error)