diff --git a/components/form/demo/horizontal-form.md b/components/form/demo/horizontal-form.md deleted file mode 100644 index f9dd76a0b7..0000000000 --- a/components/form/demo/horizontal-form.md +++ /dev/null @@ -1,88 +0,0 @@ ---- -order: 2 -title: - zh-CN: 典型表单 - en-US: Horizontal form ---- - -## zh-CN - -示例展示了如何通过使用 `Form.create` 来获取和更新表单提交的数值。 - -## en-US - -How to use `Form.create` to get and update values of form. - -````jsx -import { Form, Input, Button, Checkbox, Radio, Tooltip, Icon } from 'antd'; -const FormItem = Form.Item; -const RadioGroup = Radio.Group; - -let Demo = React.createClass({ - handleSubmit(e) { - e.preventDefault(); - console.log('Received values of form:', this.props.form.getFieldsValue()); - }, - - render() { - const { getFieldDecorator } = this.props.form; - const formItemLayout = { - labelCol: { span: 6 }, - wrapperCol: { span: 14 }, - }; - return ( -
- -

Big eye minion

-
- - {getFieldDecorator('pass', { initialValue: '' })( - - )} - - - {getFieldDecorator('gender', { initialValue: 'female' })( - - male - female - - )} - - - {getFieldDecorator('remark', { initialValue: '' })( - - )} - - Sold myself } - > - {getFieldDecorator('agreement', { initialValue: false, valuePropName: 'checked' })( - agree - )} - - - - -
- ); - }, -}); - -Demo = Form.create()(Demo); - -ReactDOM.render(, mountNode); -```` diff --git a/components/form/demo/input-group.md b/components/form/demo/input-group.md deleted file mode 100644 index 32f81bacfb..0000000000 --- a/components/form/demo/input-group.md +++ /dev/null @@ -1,105 +0,0 @@ ---- -order: 4 -title: - zh-CN: 输入框组合 - en-US: Input group ---- - -## zh-CN - -各类输入框的组合展现。 - -## en-US - -Input group of different type input controls. - -````jsx -import { Form, Input, Select, Col } from 'antd'; -const FormItem = Form.Item; -const InputGroup = Input.Group; -const Option = Select.Option; - -const selectAfter = ( - -); - -ReactDOM.render( -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

--

- - - - - - - - - - -
-
-
- -, mountNode); -```` diff --git a/components/form/demo/register.md b/components/form/demo/register.md new file mode 100644 index 0000000000..c24ff317d4 --- /dev/null +++ b/components/form/demo/register.md @@ -0,0 +1,220 @@ +--- +order: 2 +title: + zh-CN: 注册新用户 + en-US: Registration +--- + +## zh-CN + +用户填写必须的信息以注册新用户。 + +## en-US + +Fill in this form to create a new account for you. + +````jsx +import { Form, Input, Tooltip, Icon, Cascader, Select, Row, Col, Checkbox, Button } from 'antd'; +const FormItem = Form.Item; +const Option = Select.Option; + +const residences = [{ + value: 'zhejiang', + label: 'Zhejiang', + children: [{ + value: 'hangzhou', + label: 'Hangzhou', + children: [{ + value: 'xihu', + label: 'West Lake', + }], + }], +}, { + value: 'jiangsu', + label: 'Jiangsu', + children: [{ + value: 'nanjing', + label: 'Nanjing', + children: [{ + value: 'zhonghuamen', + label: 'Zhong Hua Men', + }], + }], +}]; + +const RegistrationForm = Form.create()(React.createClass({ + getInitialState() { + return { + passwordDirty: false, + }; + }, + handleSubmit(e) { + e.preventDefault(); + + this.props.form.validateFields((err, values) => { + if (err) { + return; + } + + console.log('Received values of form: ', values); + }); + }, + handlePasswordBlur(e) { + const value = e.target.value; + this.setState({ passwordDirty: this.state.passwordDirty || !!value }); + }, + checkPassowrd(rule, value, callback) { + const form = this.props.form; + if (value && value !== form.getFieldValue('password')) { + callback('Two passwords that you enter is inconsistent!'); + } else { + callback(); + } + }, + checkConfirm(rule, value, callback) { + const form = this.props.form; + if (value && this.state.passwordDirty) { + form.validateFields(['confirm'], { force: true }); + } + + callback(); + }, + render() { + const { getFieldDecorator } = this.props.form; + const formItemLayout = { + labelCol: { span: 6 }, + wrapperCol: { span: 14 }, + }; + const prefixSelector = getFieldDecorator('prefix', { + initialValue: '86', + })( + + ); + return ( +
+ + {getFieldDecorator('email', { + rules: [{ + type: 'email', message: 'The input is not valid E-mail!', + }, { + required: true, message: 'Please input your E-mail!', + }], + })( + + )} + + + {getFieldDecorator('password', { + rules: [{ + required: true, message: 'Please input your password!', + }, { + validator: this.checkConfirm, + }], + })( + + )} + + + {getFieldDecorator('confirm', { + rules: [{ + required: true, message: 'Please confirm your password!', + }, { + validator: this.checkPassowrd, + }], + })( + + )} + + + Nickname  + + + + + )} + > + {getFieldDecorator('nickname', { + rules: [{ required: true, message: 'Please input your nickname!' }], + })( + + )} + + + {getFieldDecorator('residence', { + initialValue: ['zhejiang', 'hangzhou', 'xihu'], + rules: [{ type: 'array', required: true, message: 'Please select your habitual residence!' }], + })( + + )} + + + {getFieldDecorator('phone', { + rules: [{ required: true, message: 'Please input your phone number!' }], + })( + + )} + + + + + {getFieldDecorator('captcha', { + rules: [{ required: true, message: 'Please input the captcha you got!' }], + })( + + )} + + + + + + + + + +

+ {getFieldDecorator('agreement', { + valuePropName: 'checked', + })( + I had read the agreement + )} +

+ + +
+
+
+ ); + }, +})); + +ReactDOM.render(, mountNode); +```` + +````css +#components-form-demo-register .icp-selector { + width: 60px; +} +````