Merge pull request #1287 from ant-design/feat-form-item

feat: support multi children for Form.Item
This commit is contained in:
afc163 2016-03-28 17:40:14 +08:00
commit f5ef6e58dd
2 changed files with 8 additions and 7 deletions

View File

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

View File

@ -7,7 +7,7 @@
---
````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 RadioGroup = Radio.Group;
const createForm = Form.create;
@ -134,6 +134,7 @@ let Demo = React.createClass({
<Radio value="male"></Radio>
<Radio value="female"></Radio>
</RadioGroup>
<span><Icon type="info-circle-o" /> 暂不支持其它性别</span>
</FormItem>
<FormItem