UNPKG

vue-antd-ui

Version:

An enterprise-class UI design language and Vue-based implementation

61 lines (53 loc) 1.24 kB
/* eslint react/no-multi-comp:0, no-console:0 */ import { createForm } from '../index'; var Form = { props: { form: Object }, beforeMount: function beforeMount() { this.nameDecorator = this.form.getFieldDecorator('name', { initialValue: '', rules: [{ required: true, message: 'What\'s your name?' }] }); }, methods: { onSubmit: function onSubmit(e) { e.preventDefault(); this.form.validateFields(function (error, values) { if (!error) { console.log('ok', values); } else { console.log('error', error, values); } }); }, onChange: function onChange(e) { console.log(e.target.value); } }, render: function render() { var h = arguments[0]; var getFieldError = this.form.getFieldError; return h( 'form', { on: { 'submit': this.onSubmit } }, [this.nameDecorator(h('input', { on: { 'input': this.onChange } })), h( 'div', { style: { color: 'red' } }, [(getFieldError('name') || []).join(', ')] ), h('button', ['Submit'])] ); } }; export default createForm()(Form);