/* eslint react/no-multi-comp:0, no-console:0 */
import { createForm } from '../index'
import { regionStyle, errorStyle } from './styles'
import BaseMixin from '../../_util/BaseMixin'
const Email = {
props: {
form: Object,
},
methods: {
checkSpecial (rule, value, callback) {
setTimeout(() => {
if (value === 'yiminghe@gmail.com') {
callback('can not be!')
} else {
callback()
}
}, 1000)
},
},
render () {
const { getFieldProps, getFieldError, isFieldValidating } = this.form
const errors = getFieldError('email')
return (
email validate onBlur
{errors ? errors.join(',') : null}
{isFieldValidating('email') ? 'validating' : null}
)
},
}
const Form = {
mixins: [BaseMixin],
props: {
form: Object,
},
data () {
return {
loading: true,
}
},
mounted () {
setTimeout(() => {
this.setState({
loading: false,
}, () => {
setTimeout(() => {
this.form.setFieldsInitialValue({
email: 'xx@gmail.com',
})
}, 1000)
})
}, 1000)
},
methods: {
onSubmit (e) {
e.preventDefault()
this.form.submit((callback) => {
setTimeout(() => {
this.form.validateFields((error, values) => {
if (!error) {
console.log('ok', values)
} else {
console.log('error', error, values)
}
callback()
})
}, 1000)
})
},
reset (e) {
e.preventDefault()
this.form.resetFields()
},
},
render () {
if (this.loading) {
return loading
}
const { form } = this
const disabled = form.isFieldsValidating() || form.isSubmitting()
return ()
},
}
export default createForm()(Form)