Skip to content

Instantly share code, notes, and snippets.

@jwaggener
Last active August 29, 2015 14:23
Show Gist options
  • Save jwaggener/e311a3fbe14b3e5a462d to your computer and use it in GitHub Desktop.
Save jwaggener/e311a3fbe14b3e5a462d to your computer and use it in GitHub Desktop.
var React = require('react'),
t = require('tcomb-form');
var MinimalFactory = React.createClass({
props: {
type: t.List,
onChange: React.PropTypes.func,
ctx: React.PropTypes.object
},
getInitialState: function () {
return {
value: this.props.value // the initial passed in value is ['one', 'two'];
};
},
validate: function() {
return t.validate(this.state.value, this.props.type);
},
onClick: function() {
this.setState({value: ['new', 'value']});
// why does @gcanti say this must be called?
// and is onChange injected?
//this.props.onChange(['new', 'value'], this.props.ctx.path);
},
render: function() {
return(
<div>
<h1>hello </h1>
<button onClick={this.onClick}>Change Value</button>
</div>
);
},
});
module.exports = MinimalFactory;
// relevant poriton of the file:
var value = {
tags: ['one', 'two']
};
var options = {
fields: {
tags: {
factory: MinimalistFactory
}
}
};
var tagInput = t.struct({
tags: t.list(t.Str)
});
...
<TForm ref='labelsForm'
type={tagInput}
options={options}
value={value}
/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment