feat: support multi children for Form.Item

pull/1287/head
Benjy Cui 9 years ago
parent 80f11f5f70
commit 10dd78122b

@ -28,16 +28,16 @@ export default class FormItem extends React.Component {
return props.help; return props.help;
} }
getOnlyChildren() { getOnlyControl() {
const children = React.Children.toArray(this.props.children); const children = React.Children.toArray(this.props.children);
if (children.length === 1) { const child = children.filter((c) => {
return children[0]; return c.props && '__meta' in c.props;
} })[0];
return null; return child !== undefined ? child : null;
} }
getChildProp(prop) { getChildProp(prop) {
const child = this.getOnlyChildren(); const child = this.getOnlyControl();
return child && child.props && child.props[prop]; return child && child.props && child.props[prop];
} }

@ -7,7 +7,7 @@
--- ---
````jsx ````jsx
import { Select, Radio, Checkbox, Button, DatePicker, InputNumber, Form, Cascader } from 'antd'; import { Select, Radio, Checkbox, Button, DatePicker, InputNumber, Form, Cascader, Icon } from 'antd';
const Option = Select.Option; const Option = Select.Option;
const RadioGroup = Radio.Group; const RadioGroup = Radio.Group;
const createForm = Form.create; const createForm = Form.create;
@ -134,6 +134,7 @@ let Demo = React.createClass({
<Radio value="male"></Radio> <Radio value="male"></Radio>
<Radio value="female"></Radio> <Radio value="female"></Radio>
</RadioGroup> </RadioGroup>
<span><Icon type="info-circle-o" /> 暂不支持其它性别</span>
</FormItem> </FormItem>
<FormItem <FormItem

Loading…
Cancel
Save