Last active
August 29, 2015 14:23
-
-
Save jwaggener/e311a3fbe14b3e5a462d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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