import React from "react"; import styles from "./index.less"; import { Form, Input, Tooltip, Icon, Cascader, Select, Row, Col, Checkbox, Button, AutoComplete } from "antd"; const { Option } = Select; const AutoCompleteOption = AutoComplete.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" } ] } ] } ]; class RegistrationForm extends React.Component { state = { confirmDirty: false, autoCompleteResult: [] }; handleSubmit = e => { e.preventDefault(); this.props.form.validateFieldsAndScroll((err, values) => { if (!err) { console.log("Received values of form: ", values); } }); }; handleConfirmBlur = e => { const { value } = e.target; this.setState({ confirmDirty: this.state.confirmDirty || !!value }); }; compareToFirstPassword = (rule, value, callback) => { const { form } = this.props; if (value && value !== form.getFieldValue("password")) { callback("Two passwords that you enter is inconsistent!"); } else { callback(); } }; validateToNextPassword = (rule, value, callback) => { const { form } = this.props; if (value && this.state.confirmDirty) { form.validateFields(["confirm"], { force: true }); } callback(); }; handleWebsiteChange = value => { let autoCompleteResult; if (!value) { autoCompleteResult = []; } else { autoCompleteResult = [".com", ".org", ".net"].map( domain => `${value}${domain}` ); } this.setState({ autoCompleteResult }); }; render() { const { getFieldDecorator } = this.props.form; const { autoCompleteResult } = this.state; const formItemLayout = { labelCol: { xs: { span: 24 }, sm: { span: 8 } }, wrapperCol: { xs: { span: 24 }, sm: { span: 16 } } }; const tailFormItemLayout = { wrapperCol: { xs: { span: 24, offset: 0 }, sm: { span: 16, offset: 8 } } }; const prefixSelector = getFieldDecorator("prefix", { initialValue: "86" })( ); const websiteOptions = autoCompleteResult.map(website => ( {website} )); 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.validateToNextPassword } ] })()} {getFieldDecorator("confirm", { rules: [ { required: true, message: "Please confirm your password!" }, { validator: this.compareToFirstPassword } ] })()} Nickname  } > {getFieldDecorator("nickname", { rules: [ { required: true, message: "Please input your nickname!", whitespace: true } ] })()} {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("website", { rules: [{ required: true, message: "Please input website!" }] })( )} {getFieldDecorator("captcha", { rules: [ { required: true, message: "Please input the captcha you got!" } ] })()} {getFieldDecorator("agreement", { valuePropName: "checked" })( I have read the agreement )}
); } } const WrappedRegistrationForm = Form.create({ name: "register" })( RegistrationForm ); export default () => (
);