|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
import React from 'react';
|
|
|
|
|
import classNames from 'classnames';
|
|
|
|
|
import objectAssign from 'object-assign';
|
|
|
|
|
|
|
|
|
|
function prefixClsFn(prefixCls, ...args) {
|
|
|
|
|
return args.map((s) => {
|
|
|
|
@ -32,10 +33,6 @@ class FormItem extends React.Component {
|
|
|
|
|
return this.props.children.props && this.props.children.props.id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getMeta() {
|
|
|
|
|
return this.props.children.props && this.props.children.props.__meta;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderHelp() {
|
|
|
|
|
const props = this.props;
|
|
|
|
|
const prefixCls = props.prefixCls;
|
|
|
|
@ -97,8 +94,13 @@ class FormItem extends React.Component {
|
|
|
|
|
|
|
|
|
|
isRequired() {
|
|
|
|
|
if (this.context.form) {
|
|
|
|
|
const meta = this.getMeta() || {};
|
|
|
|
|
return (meta.validate || []).some((item) => {
|
|
|
|
|
const meta = this.props.fieldOption || {};
|
|
|
|
|
|
|
|
|
|
// Have to merge manually, for children have no `__meta` now.
|
|
|
|
|
const validate = (meta.validate || []);
|
|
|
|
|
validate.push({ rules: meta.rules });
|
|
|
|
|
|
|
|
|
|
return validate.filter((item) => !!item.rules).some((item) => {
|
|
|
|
|
return item.rules.some((rule) => rule.required);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
@ -120,12 +122,23 @@ class FormItem extends React.Component {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderChildren() {
|
|
|
|
|
const context = this.context;
|
|
|
|
|
const props = this.props;
|
|
|
|
|
const children = React.Children.map(props.children, (child) => {
|
|
|
|
|
// If <Component /> <Component />,
|
|
|
|
|
// React will not convert into component.
|
|
|
|
|
if (!child.type) {
|
|
|
|
|
return child;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const childProps = {};
|
|
|
|
|
if (typeof child.type === 'function' && !child.props.size) {
|
|
|
|
|
return React.cloneElement(child, { size: 'large' });
|
|
|
|
|
objectAssign(childProps, { size: 'large' });
|
|
|
|
|
}
|
|
|
|
|
return child;
|
|
|
|
|
if (context.form && this.getId()) {
|
|
|
|
|
objectAssign(childProps, context.form.getFieldProps(this.getId(), props.fieldOption));
|
|
|
|
|
}
|
|
|
|
|
return React.cloneElement(child, childProps);
|
|
|
|
|
});
|
|
|
|
|
return [
|
|
|
|
|
this.renderLabel(),
|
|
|
|
|