2018-05-06 10:32:40 +00:00
|
|
|
<cn>
|
|
|
|
#### 表单联动
|
|
|
|
使用 `setFieldsValue` 来动态设置其他控件的值。
|
|
|
|
</cn>
|
|
|
|
|
|
|
|
<us>
|
|
|
|
#### Coordinated Controls
|
|
|
|
Use `setFieldsValue` to set other control's value programmaticly.
|
|
|
|
</us>
|
|
|
|
|
2018-06-23 09:17:45 +00:00
|
|
|
<template>
|
2019-09-28 12:45:07 +00:00
|
|
|
<a-form :form="form" @submit="handleSubmit">
|
|
|
|
<a-form-item label="Note" :label-col="{ span: 5 }" :wrapper-col="{ span: 12 }">
|
2018-12-07 13:27:47 +00:00
|
|
|
<a-input
|
2019-09-28 12:45:07 +00:00
|
|
|
v-decorator="['note', { rules: [{ required: true, message: 'Please input your note!' }] }]"
|
2018-12-07 13:27:47 +00:00
|
|
|
/>
|
2018-06-23 09:17:45 +00:00
|
|
|
</a-form-item>
|
2019-09-28 12:45:07 +00:00
|
|
|
<a-form-item label="Gender" :label-col="{ span: 5 }" :wrapper-col="{ span: 12 }">
|
2018-06-23 09:17:45 +00:00
|
|
|
<a-select
|
2018-12-07 13:27:47 +00:00
|
|
|
v-decorator="[
|
|
|
|
'gender',
|
2019-09-28 12:45:07 +00:00
|
|
|
{ rules: [{ required: true, message: 'Please select your gender!' }] },
|
2018-12-07 13:27:47 +00:00
|
|
|
]"
|
2019-02-01 09:23:00 +00:00
|
|
|
placeholder="Select a option and change input text above"
|
|
|
|
@change="handleSelectChange"
|
2018-06-23 09:17:45 +00:00
|
|
|
>
|
2019-02-01 09:23:00 +00:00
|
|
|
<a-select-option value="male">
|
|
|
|
male
|
|
|
|
</a-select-option>
|
|
|
|
<a-select-option value="female">
|
|
|
|
female
|
|
|
|
</a-select-option>
|
2018-06-23 09:17:45 +00:00
|
|
|
</a-select>
|
|
|
|
</a-form-item>
|
2019-09-28 12:45:07 +00:00
|
|
|
<a-form-item :wrapper-col="{ span: 12, offset: 5 }">
|
|
|
|
<a-button type="primary" html-type="submit">
|
2018-06-23 09:17:45 +00:00
|
|
|
Submit
|
|
|
|
</a-button>
|
|
|
|
</a-form-item>
|
|
|
|
</a-form>
|
|
|
|
</template>
|
2018-05-06 10:32:40 +00:00
|
|
|
|
2018-06-23 09:17:45 +00:00
|
|
|
<script>
|
|
|
|
export default {
|
2019-09-28 12:45:07 +00:00
|
|
|
data() {
|
2018-06-23 09:17:45 +00:00
|
|
|
return {
|
|
|
|
formLayout: 'horizontal',
|
2019-04-20 06:19:13 +00:00
|
|
|
form: this.$form.createForm(this, { name: 'coordinated' }),
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2018-06-23 09:17:45 +00:00
|
|
|
},
|
2018-05-06 10:32:40 +00:00
|
|
|
methods: {
|
2019-09-28 12:45:07 +00:00
|
|
|
handleSubmit(e) {
|
2019-01-12 03:33:27 +00:00
|
|
|
e.preventDefault();
|
2018-05-06 10:32:40 +00:00
|
|
|
this.form.validateFields((err, values) => {
|
|
|
|
if (!err) {
|
2019-01-12 03:33:27 +00:00
|
|
|
console.log('Received values of form: ', values);
|
2018-05-06 10:32:40 +00:00
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2018-05-06 10:32:40 +00:00
|
|
|
},
|
2019-09-28 12:45:07 +00:00
|
|
|
handleSelectChange(value) {
|
2019-01-12 03:33:27 +00:00
|
|
|
console.log(value);
|
2018-05-06 10:32:40 +00:00
|
|
|
this.form.setFieldsValue({
|
|
|
|
note: `Hi, ${value === 'male' ? 'man' : 'lady'}!`,
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
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>
|