2016-07-29 11:18:31 +08:00
|
|
|
import React, { PropTypes } from 'react';
|
|
|
|
import createDOMForm from 'rc-form/lib/createDOMForm';
|
2015-10-09 13:53:04 +08:00
|
|
|
import Form from './Form';
|
|
|
|
import FormItem from './FormItem';
|
2015-10-25 11:34:31 +08:00
|
|
|
import ValueMixin from './ValueMixin';
|
2016-06-22 13:18:43 +08:00
|
|
|
import assign from 'object-assign';
|
2016-07-07 16:59:47 +08:00
|
|
|
import { FIELD_META_PROP } from './constants';
|
2015-10-09 13:53:04 +08:00
|
|
|
|
2016-01-28 21:43:45 +08:00
|
|
|
Form.create = (o = {}) => {
|
2016-06-22 13:18:43 +08:00
|
|
|
const options = assign({}, o, {
|
2016-01-28 21:43:45 +08:00
|
|
|
fieldNameProp: 'id',
|
2016-07-07 16:59:47 +08:00
|
|
|
fieldMetaProp: FIELD_META_PROP,
|
2016-06-22 13:18:43 +08:00
|
|
|
});
|
2016-07-29 11:18:31 +08:00
|
|
|
const formWrapper = createDOMForm(options);
|
2016-01-28 21:43:45 +08:00
|
|
|
|
2016-07-29 11:18:31 +08:00
|
|
|
/* eslint-disable react/prefer-es6-class */
|
|
|
|
return (Component) => formWrapper(React.createClass({
|
|
|
|
propTypes: {
|
|
|
|
form: PropTypes.object.isRequired,
|
|
|
|
},
|
|
|
|
childContextTypes: {
|
|
|
|
form: PropTypes.object.isRequired,
|
|
|
|
},
|
|
|
|
getChildContext() {
|
|
|
|
return {
|
|
|
|
form: this.props.form,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
render() {
|
|
|
|
return <Component {...this.props} />;
|
|
|
|
},
|
|
|
|
}));
|
2016-01-28 21:43:45 +08:00
|
|
|
};
|
2016-07-29 13:57:54 +08:00
|
|
|
|
2015-10-09 13:53:04 +08:00
|
|
|
Form.Item = FormItem;
|
2016-01-22 14:31:08 +08:00
|
|
|
|
|
|
|
// @Deprecated
|
2015-10-25 11:34:31 +08:00
|
|
|
Form.ValueMixin = ValueMixin;
|
2015-11-20 18:51:12 +08:00
|
|
|
|
2015-11-20 18:21:59 +08:00
|
|
|
export default Form;
|