# 其他表单域校验 - order: 1 提供以下组件表单域的校验。 `Select` `Radio` `Datepicker` `InputNumber`。 --- ````jsx import {Validation, Select, Radio, Button, Datepicker, InputNumber, Form} from 'antd'; const Validator = Validation.Validator; const Option = Select.Option; const RadioGroup = Radio.Group; const FormItem = Form.Item; function cx(classNames) { if (typeof classNames === 'object') { return Object.keys(classNames).filter(function(className) { return classNames[className]; }).join(' '); } else { return Array.prototype.join.call(arguments, ' '); } } function noop() { return false; } const Demo = React.createClass({ mixins: [Validation.FieldMixin], getInitialState() { return { status: { select: {}, multiSelect: {}, radio: {}, birthday: {}, primeNumber: {} }, formData: { select: undefined, multiSelect: undefined, radio: undefined, birthday: undefined, primeNumber: 9 } }; }, renderValidateStyle(item) { const formData = this.state.formData; const status = this.state.status; const classes = cx({ 'error': status[item].errors, 'validating': status[item].isValidating, 'success': formData[item] && !status[item].errors && !status[item].isValidating }); return classes; }, handleReset(e) { this.refs.validation.reset(); this.setState(this.getInitialState()); e.preventDefault(); }, handleSubmit(e) { e.preventDefault(); this.setState({ isEmailOver: true }); const validation = this.refs.validation; validation.validate((valid) => { if (!valid) { console.log('error in form'); return; } else { console.log('submit'); } console.log(this.state.formData); }); }, checkBirthday(rule, value, callback) { if (value && value.getTime() >= Date.now()){ callback(new Error('你不可能在未来出生吧!')); } else { callback(); } }, checkPrime(rule, value, callback) { if (value !== 11) { callback(new Error('8~12之间的质数明明是11啊!')); } else { callback(); } }, render() { const formData = this.state.formData; const status = this.state.status; return (
); } }); ReactDOM.render(