2018-05-06 10:32:40 +00:00
|
|
|
|
<cn>
|
|
|
|
|
#### 弹出层中的新建表单
|
|
|
|
|
当用户访问一个展示了某个列表的页面,想新建一项但又不想跳转页面时,可以用 Modal 弹出一个表单,用户填写必要信息后创建新的项。
|
|
|
|
|
</cn>
|
|
|
|
|
|
|
|
|
|
<us>
|
|
|
|
|
#### Form in Modal to Create
|
|
|
|
|
When user visit a page with a list of items, and want to create a new item. The page can popup a form in Modal, then let user fill in the form to create an item.
|
|
|
|
|
</us>
|
|
|
|
|
|
2018-12-07 13:27:47 +00:00
|
|
|
|
<template>
|
|
|
|
|
<div>
|
2019-02-01 09:23:00 +00:00
|
|
|
|
<a-button
|
|
|
|
|
type="primary"
|
|
|
|
|
@click="showModal"
|
|
|
|
|
>
|
|
|
|
|
New Collection
|
|
|
|
|
</a-button>
|
2018-12-07 13:27:47 +00:00
|
|
|
|
<collection-create-form
|
|
|
|
|
ref="collectionForm"
|
|
|
|
|
:visible="visible"
|
|
|
|
|
@cancel="handleCancel"
|
|
|
|
|
@create="handleCreate"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
2018-05-08 03:20:07 +00:00
|
|
|
|
|
2018-05-06 10:32:40 +00:00
|
|
|
|
<script>
|
2018-12-07 13:27:47 +00:00
|
|
|
|
const CollectionCreateForm = {
|
|
|
|
|
props: ['visible'],
|
|
|
|
|
beforeCreate () {
|
2019-04-20 06:19:13 +00:00
|
|
|
|
this.form = this.$form.createForm(this, { name: 'form_in_modal' });
|
2018-12-07 13:27:47 +00:00
|
|
|
|
},
|
|
|
|
|
template: `
|
|
|
|
|
<a-modal
|
|
|
|
|
:visible="visible"
|
|
|
|
|
title='Create a new collection'
|
|
|
|
|
okText='Create'
|
|
|
|
|
@cancel="() => { $emit('cancel') }"
|
|
|
|
|
@ok="() => { $emit('create') }"
|
|
|
|
|
>
|
|
|
|
|
<a-form layout='vertical' :form="form">
|
|
|
|
|
<a-form-item label='Title'>
|
|
|
|
|
<a-input
|
|
|
|
|
v-decorator="[
|
|
|
|
|
'title',
|
|
|
|
|
{
|
2018-05-06 10:32:40 +00:00
|
|
|
|
rules: [{ required: true, message: 'Please input the title of collection!' }],
|
2018-12-07 13:27:47 +00:00
|
|
|
|
}
|
|
|
|
|
]"
|
|
|
|
|
/>
|
|
|
|
|
</a-form-item>
|
|
|
|
|
<a-form-item label='Description'>
|
|
|
|
|
<a-input
|
|
|
|
|
type='textarea'
|
|
|
|
|
v-decorator="['description']"
|
|
|
|
|
/>
|
|
|
|
|
</a-form-item>
|
|
|
|
|
<a-form-item class='collection-create-form_last-form-item'>
|
|
|
|
|
<a-radio-group
|
|
|
|
|
v-decorator="[
|
|
|
|
|
'modifier',
|
|
|
|
|
{
|
|
|
|
|
initialValue: 'private',
|
|
|
|
|
}
|
|
|
|
|
]"
|
|
|
|
|
>
|
|
|
|
|
<a-radio value='public'>Public</a-radio>
|
|
|
|
|
<a-radio value='private'>Private</a-radio>
|
|
|
|
|
</a-radio-group>
|
|
|
|
|
</a-form-item>
|
|
|
|
|
</a-form>
|
|
|
|
|
</a-modal>
|
|
|
|
|
`,
|
2019-01-12 03:33:27 +00:00
|
|
|
|
};
|
2018-05-06 10:32:40 +00:00
|
|
|
|
|
|
|
|
|
export default {
|
2019-02-01 09:23:00 +00:00
|
|
|
|
components: { CollectionCreateForm },
|
2018-05-06 10:32:40 +00:00
|
|
|
|
data () {
|
|
|
|
|
return {
|
|
|
|
|
visible: false,
|
2019-01-12 03:33:27 +00:00
|
|
|
|
};
|
2018-05-06 10:32:40 +00:00
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
showModal () {
|
2019-01-12 03:33:27 +00:00
|
|
|
|
this.visible = true;
|
2018-05-06 10:32:40 +00:00
|
|
|
|
},
|
|
|
|
|
handleCancel () {
|
2019-01-12 03:33:27 +00:00
|
|
|
|
this.visible = false;
|
2018-05-06 10:32:40 +00:00
|
|
|
|
},
|
|
|
|
|
handleCreate () {
|
2019-01-12 03:33:27 +00:00
|
|
|
|
const form = this.$refs.collectionForm.form;
|
2018-05-06 10:32:40 +00:00
|
|
|
|
form.validateFields((err, values) => {
|
|
|
|
|
if (err) {
|
2019-01-12 03:33:27 +00:00
|
|
|
|
return;
|
2018-05-06 10:32:40 +00:00
|
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
|
console.log('Received values of form: ', values);
|
|
|
|
|
form.resetFields();
|
|
|
|
|
this.visible = false;
|
|
|
|
|
});
|
2018-05-06 10:32:40 +00:00
|
|
|
|
},
|
|
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
|
};
|
2018-05-06 10:32:40 +00:00
|
|
|
|
</script>
|
2018-05-08 03:20:07 +00:00
|
|
|
|
|
2018-05-06 10:32:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-12-07 13:27:47 +00:00
|
|
|
|
|