{"size": 1127, "ext": "js", "max_stars_repo_path": "examples/setFieldsValue.js", "max_stars_repo_name": "setState/form", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "examples/setFieldsValue.js", "max_issues_repo_name": "setState/form", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "examples/setFieldsValue.js", "max_forks_repo_name": "setState/form", "max_forks_repo_forks_event_min_datetime": "2016-12-26T02:41:56.000Z", "max_forks_repo_forks_event_max_datetime": "2016-12-26T02:41:56.000Z"}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 21.2641509434, "max_line_length": 69, "alphanum_fraction": 0.562555457}
/* eslint react/no-multi-comp:0, no-console:0 */

import { createForm } from 'rc-form';
import React, { PropTypes } from 'react';
import ReactDOM from 'react-dom';
import { regionStyle, errorStyle } from './styles';

let Form = React.createClass({
  propTypes: {
    form: PropTypes.object,
  },

  setEmail() {
    this.props.form.setFieldsValue({
      email: 'yiminghe@gmail.com',
    });
  },

  render() {
    const { getFieldProps, getFieldError } = this.props.form;
    const errors = getFieldError('email');
    return (<div style={ regionStyle }>
      <div>email:</div>
      <div>
        <input {...getFieldProps('email', {
          rules: [{
            type: 'email',
          }],
        })}
        />
      </div>
      <div style={errorStyle}>
        {(errors) ? errors.join(',') : null}
      </div>

      <button onClick={this.setEmail}>set</button>
    </div>);
  },
});

Form = createForm()(Form);

class App extends React.Component {
  render() {
    return (<div>
      <h2>setFieldsValue</h2>
      <Form />
    </div>);
  }
}

ReactDOM.render(<App />, document.getElementById('__react-content'));
