/* eslint react/no-multi-comp:0, no-console:0 */ import { createForm } from '../index'; import { regionStyle, errorStyle } from './styles'; const Email = { props: { form: Object, }, render() { const { getFieldProps, getFieldError, isFieldValidating } = this.form; const errors = getFieldError('email'); return (
email sync validate
{errors ? errors.join(',') : null}
{isFieldValidating('email') ? 'validating' : null}
); }, }; const User = { props: { form: Object, }, methods: { userExists(rule, value, callback) { setTimeout(() => { if (value === '1') { callback([new Error('are you kidding?')]); } else if (value === 'yiminghe') { callback([new Error('forbid yiminghe')]); } else { callback(); } }, 300); }, }, render() { const { getFieldProps, getFieldError, isFieldValidating } = this.form; const errors = getFieldError('user'); return (
user async validate
{errors ? errors.join(',') : null}
{isFieldValidating('user') ? 'validating' : null}
); }, }; const Form = { methods: { onSubmit(e) { console.log('submit'); e.preventDefault(); this.form.validateFields( { // firstFields: false, }, (error, values) => { if (!error) { console.log('ok', values); } else { console.log('error', error, values); } }, ); }, reset(e) { e.preventDefault(); this.form.resetFields(); }, }, render() { const { form } = this; return (

validateFirst

 
); }, }; export default createForm()(Form);