Currently we need to set up state by ourselves in order to set error message at runtime (e.g. when showing an error message from server API), as discussed in this issue #19.
I thought it'd be much simpler to have the error message in the components' state and then change the error message directly.
After the this change, this code can be written as below
var RegisterForm = React.createClass({
...
onClick: function(evt) {
evt.preventDefault();
var values = this.refs.registerForm.getValue();
if (values) {
var errors = sendDataToServer(values);
if (errors.email) {
var emailComp = this.refs.registerForm.getComponent('email')
emailComp.setState({ hasError: true, error: errors.email })
}
}
},
...
render: function() {
var Form = t.form.createForm(Model, {
fields: {
email: {
type: 'email',
label: 'Email',
}
}
});
Currently we need to set up state by ourselves in order to set error message at runtime (e.g. when showing an error message from server API), as discussed in this issue #19.
I thought it'd be much simpler to have the error message in the components' state and then change the error message directly.
After the this change, this code can be written as below