/* eslint react/no-multi-comp:0, no-console:0 */ import createDOMForm from '../src/createDOMForm' import { DatePicker, Select } from 'vue-antd-ui' import { regionStyle, errorStyle } from './styles' const { Option } = Select const Email = { props: { form: Object, }, render () { const { getFieldProps, getFieldError, isFieldValidating } = this.form const errors = getFieldError('email') return (
email sync validate
错误的 email 格式, }, ], })} />
{errors}
{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 CustomInput = { props: { form: Object, }, render () { const { getFieldProps, getFieldError, isFieldValidating } = this.form const errors = getFieldError('select') return (
* custom select sync validate
{(errors) ? errors.join(',') : null}
{isFieldValidating('select') ? 'validating' : null}
) }, } const DateInput = { props: { form: Object, }, render () { const { getFieldProps, getFieldError } = this.form const errors = getFieldError('date') return (
* DateInput sync validate
{(errors) ? errors.join(',') : null}
) }, } function toNumber (v) { if (v === undefined) { return v } if (v === '') { return undefined } if (v && v.trim() === '') { return NaN } return Number(v) } const NumberInput = { props: { form: Object, }, render () { const { getFieldProps, getFieldError } = this.form const errors = getFieldError('number') return (
number input
{(errors) ? errors.join(',') : null}
) }, } const Form = { methods: { onSubmit (e) { console.log('submit') e.preventDefault() this.form.validateFieldsAndScroll({ scroll: { offsetTop: 20 }}, (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 const { getFieldProps, getFieldError } = form return (

overview

normal required input
{(getFieldError('normal')) ? getFieldError('normal').join(',') : null}
 
) }, } export default createDOMForm({ validateMessages: { required (field) { return `${field} 必填` }, }, })(Form)