ant-design-vue/components/vc-form/demo/parallel-form.js

84 lines
1.5 KiB
JavaScript
Raw Normal View History

2018-05-04 11:11:42 +00:00
/* eslint react/no-multi-comp:0, no-console:0 */
2019-01-12 03:33:27 +00:00
import { createForm } from '../index';
import { regionStyle } from './styles';
import { Switch } from 'ant-design-vue';
2018-05-04 11:11:42 +00:00
const TopForm = {
props: {
form: Object,
},
2019-01-12 03:33:27 +00:00
render() {
const { getFieldProps } = this.form;
return (
<div style={regionStyle}>
2019-01-12 03:33:27 +00:00
<div>has email?</div>
<div>
2019-01-12 03:33:27 +00:00
<Switch {...getFieldProps('on', { initialValue: true, valuePropName: 'checked' })} />
</div>
2018-05-04 11:11:42 +00:00
</div>
2019-01-12 03:33:27 +00:00
);
2018-05-04 11:11:42 +00:00
},
2019-01-12 03:33:27 +00:00
};
2018-05-04 11:11:42 +00:00
const BottomForm = {
props: {
form: Object,
on: Boolean,
},
2019-01-12 03:33:27 +00:00
render() {
const { form } = this;
const on = form.getFieldValue('on');
2018-05-04 11:11:42 +00:00
const style = {
...regionStyle,
display: on ? 'block' : 'none',
2019-01-12 03:33:27 +00:00
};
return (
<div style={style}>
<div>email:</div>
<div>
2019-01-12 03:33:27 +00:00
<input {...form.getFieldProps('email', { rules: [{ type: 'email' }], hidden: !on })} />
</div>
2018-05-04 11:11:42 +00:00
</div>
2019-01-12 03:33:27 +00:00
);
2018-05-04 11:11:42 +00:00
},
2019-01-12 03:33:27 +00:00
};
2018-05-04 11:11:42 +00:00
const Form = {
props: {
form: Object,
},
methods: {
2019-01-12 03:33:27 +00:00
onSubmit(e) {
e.preventDefault();
console.log(this.form.getFieldsValue());
2018-05-04 11:11:42 +00:00
},
},
2019-01-12 03:33:27 +00:00
render() {
const { form } = this;
return (
<div>
2019-01-12 03:33:27 +00:00
<TopForm form={form} />
<BottomForm form={form} />
<div style={regionStyle}>
<button onClick={this.onSubmit}>submit</button>
</div>
2018-05-04 11:11:42 +00:00
</div>
2019-01-12 03:33:27 +00:00
);
2018-05-04 11:11:42 +00:00
},
2019-01-12 03:33:27 +00:00
};
2018-05-04 11:11:42 +00:00
2019-01-12 03:33:27 +00:00
const NewForm = createForm()(Form);
2018-05-04 11:11:42 +00:00
export default {
2019-01-12 03:33:27 +00:00
render() {
return (
<div>
<h2>parallel form</h2>
2019-01-12 03:33:27 +00:00
<NewForm />
</div>
2019-01-12 03:33:27 +00:00
);
2018-05-04 11:11:42 +00:00
},
2019-01-12 03:33:27 +00:00
};