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

92 lines
2.1 KiB
JavaScript
Raw Normal View History

2018-05-04 08:02:31 +00:00
/* eslint react/no-multi-comp:0, no-console:0 */
2019-01-12 03:33:27 +00:00
import BaseMixin from '../../_util/BaseMixin';
import createDOMForm from '../src/createDOMForm';
import { Modal } from 'ant-design-vue';
import { regionStyle, errorStyle } from './styles';
2018-05-04 08:02:31 +00:00
const Form = {
mixins: [BaseMixin],
props: {
form: Object,
},
2019-01-12 03:33:27 +00:00
data() {
return { visible: false };
2018-05-04 08:02:31 +00:00
},
methods: {
2019-01-12 03:33:27 +00:00
onSubmit(e) {
e.preventDefault();
2018-05-04 08:02:31 +00:00
this.form.validateFieldsAndScroll((error, values) => {
if (!error) {
2019-01-12 03:33:27 +00:00
console.log('ok', values);
2018-05-04 08:02:31 +00:00
} else {
2019-01-12 03:33:27 +00:00
console.log('error', error, values);
2018-05-04 08:02:31 +00:00
}
2019-01-12 03:33:27 +00:00
});
2018-05-04 08:02:31 +00:00
},
2019-01-12 03:33:27 +00:00
onCancel() {
this.setState({ visible: false });
2018-05-04 08:02:31 +00:00
},
2019-01-12 03:33:27 +00:00
open() {
this.setState({ visible: true });
2018-05-04 08:02:31 +00:00
},
},
2019-01-12 03:33:27 +00:00
render() {
const { getFieldProps, getFieldError } = this.form;
return (
2019-01-12 03:33:27 +00:00
<div
style={{
margin: '20px',
}}
>
<h2>modal</h2>
<Modal
visible={this.visible}
bodyStyle={{
height: '200px',
overflow: 'auto',
}}
onCancel={this.onCancel}
2019-01-12 03:33:27 +00:00
title="modal"
>
<div ref="dialogContent">
<form onSubmit={this.onSubmit}>
<input
2019-01-12 03:33:27 +00:00
{...getFieldProps('required', { rules: [{ required: true, message: '必填' }] })}
/>
<div style={errorStyle}>
2019-01-12 03:33:27 +00:00
{getFieldError('required') ? (
getFieldError('required').join(',')
) : (
<b
style={{
visibility: 'hidden',
}}
>
1
</b>
)}
</div>
2019-01-12 03:33:27 +00:00
<div
style={{
marginTop: '300px',
}}
>
<button>submit</button>
</div>
</form>
</div>
</Modal>
<div style={regionStyle}>
<button onClick={this.open}>open</button>
2018-05-04 08:02:31 +00:00
</div>
</div>
2019-01-12 03:33:27 +00:00
);
2018-05-04 08:02:31 +00:00
},
2019-01-12 03:33:27 +00:00
};
export default createDOMForm()(Form);