ant-design-vue/components/form/demo/validate-other.vue

236 lines
6.0 KiB
Vue
Raw Normal View History

2018-05-06 21:53:00 +08:00
<cn>
#### 校验其他组件
以上演示没有出现的表单控件对应的校验演示
</cn>
<us>
#### Other Form Controls
2019-04-20 14:19:13 +08:00
Demonstration of validation configuration for form controls which are not shown in the demos above.
2018-05-06 21:53:00 +08:00
</us>
<template>
2019-09-28 20:45:07 +08:00
<a-form id="components-form-demo-validate-other" :form="form" @submit="handleSubmit">
<a-form-item v-bind="formItemLayout" label="Plain Text">
2019-02-01 17:23:00 +08:00
<span class="ant-form-text">
China
</span>
</a-form-item>
2019-09-28 20:45:07 +08:00
<a-form-item v-bind="formItemLayout" label="Select" has-feedback>
2019-02-01 17:23:00 +08:00
<a-select
v-decorator="[
'select',
2019-09-28 20:45:07 +08:00
{ rules: [{ required: true, message: 'Please select your country!' }] },
2019-02-01 17:23:00 +08:00
]"
placeholder="Please select a country"
>
<a-select-option value="china">
China
</a-select-option>
<a-select-option value="usa">
U.S.A
</a-select-option>
</a-select>
</a-form-item>
2019-09-28 20:45:07 +08:00
<a-form-item v-bind="formItemLayout" label="Select[multiple]">
2019-02-01 17:23:00 +08:00
<a-select
v-decorator="[
2019-09-28 20:45:07 +08:00
'select-multiple',
{
rules: [
{ required: true, message: 'Please select your favourite colors!', type: 'array' },
],
},
]"
2019-02-01 17:23:00 +08:00
mode="multiple"
placeholder="Please select favourite colors"
>
<a-select-option value="red">
Red
</a-select-option>
<a-select-option value="green">
Green
</a-select-option>
<a-select-option value="blue">
Blue
</a-select-option>
</a-select>
</a-form-item>
2019-09-28 20:45:07 +08:00
<a-form-item v-bind="formItemLayout" label="InputNumber">
<a-input-number v-decorator="['input-number', { initialValue: 3 }]" :min="1" :max="10" />
2019-02-01 17:23:00 +08:00
<span class="ant-form-text">
machines
</span>
</a-form-item>
2019-09-28 20:45:07 +08:00
<a-form-item v-bind="formItemLayout" label="Switch">
2019-02-01 17:23:00 +08:00
<a-switch v-decorator="['switch', { valuePropName: 'checked' }]" />
</a-form-item>
2019-09-28 20:45:07 +08:00
<a-form-item v-bind="formItemLayout" label="Slider">
2019-02-01 17:23:00 +08:00
<a-slider
v-decorator="['slider']"
:marks="{ 0: 'A', 20: 'B', 40: 'C', 60: 'D', 80: 'E', 100: 'F' }"
/>
</a-form-item>
2019-09-28 20:45:07 +08:00
<a-form-item v-bind="formItemLayout" label="Radio.Group">
2019-02-01 17:23:00 +08:00
<a-radio-group v-decorator="['radio-group']">
<a-radio value="a">
item 1
</a-radio>
<a-radio value="b">
item 2
</a-radio>
<a-radio value="c">
item 3
</a-radio>
</a-radio-group>
</a-form-item>
2019-09-28 20:45:07 +08:00
<a-form-item v-bind="formItemLayout" label="Radio.Button">
2019-02-01 17:23:00 +08:00
<a-radio-group v-decorator="['radio-button']">
<a-radio-button value="a">
item 1
</a-radio-button>
<a-radio-button value="b">
item 2
</a-radio-button>
<a-radio-button value="c">
item 3
</a-radio-button>
</a-radio-group>
</a-form-item>
2019-09-28 20:45:07 +08:00
<a-form-item v-bind="formItemLayout" label="Checkbox.Group">
2019-02-01 17:23:00 +08:00
<a-checkbox-group
2019-09-28 20:45:07 +08:00
v-decorator="['checkbox-group', { initialValue: ['A', 'B'] }]"
2019-02-01 17:23:00 +08:00
style="width: 100%;"
>
<a-row>
<a-col :span="8">
<a-checkbox value="A">
A
</a-checkbox>
</a-col>
<a-col :span="8">
2019-09-28 20:45:07 +08:00
<a-checkbox disabled value="B">
2019-02-01 17:23:00 +08:00
B
</a-checkbox>
</a-col>
<a-col :span="8">
<a-checkbox value="C">
C
</a-checkbox>
</a-col>
<a-col :span="8">
<a-checkbox value="D">
D
</a-checkbox>
</a-col>
<a-col :span="8">
<a-checkbox value="E">
E
</a-checkbox>
</a-col>
</a-row>
</a-checkbox-group>
</a-form-item>
2019-09-28 20:45:07 +08:00
<a-form-item v-bind="formItemLayout" label="Rate">
<a-rate v-decorator="['rate', { initialValue: 3.5 }]" allow-half />
2019-02-01 17:23:00 +08:00
</a-form-item>
<a-form-item
v-bind="formItemLayout"
label="Upload"
extra="longgggggggggggggggggggggggggggggggggg"
>
<a-upload
2019-09-28 20:45:07 +08:00
v-decorator="[
'upload',
{
valuePropName: 'fileList',
getValueFromEvent: normFile,
},
]"
2019-02-01 17:23:00 +08:00
name="logo"
action="/upload.do"
list-type="picture"
>
2019-09-28 20:45:07 +08:00
<a-button> <a-icon type="upload" /> Click to upload </a-button>
2019-02-01 17:23:00 +08:00
</a-upload>
</a-form-item>
2019-09-28 20:45:07 +08:00
<a-form-item v-bind="formItemLayout" label="Dragger">
2019-02-01 17:23:00 +08:00
<div class="dropbox">
<a-upload-dragger
2019-09-28 20:45:07 +08:00
v-decorator="[
'dragger',
{
valuePropName: 'fileList',
getValueFromEvent: normFile,
},
]"
2019-02-01 17:23:00 +08:00
name="files"
action="/upload.do"
>
<p class="ant-upload-drag-icon">
<a-icon type="inbox" />
</p>
<p class="ant-upload-text">
Click or drag file to this area to upload
</p>
<p class="ant-upload-hint">
Support for a single or bulk upload.
</p>
</a-upload-dragger>
</div>
</a-form-item>
2019-09-28 20:45:07 +08:00
<a-form-item :wrapper-col="{ span: 12, offset: 6 }">
<a-button type="primary" html-type="submit">
2019-02-01 17:23:00 +08:00
Submit
</a-button>
</a-form-item>
</a-form>
</template>
2018-05-06 21:53:00 +08:00
<script>
export default {
data: () => ({
formItemLayout: {
labelCol: { span: 6 },
wrapperCol: { span: 14 },
},
}),
2019-09-28 20:45:07 +08:00
beforeCreate() {
2019-04-20 14:19:13 +08:00
this.form = this.$form.createForm(this, { name: 'validate_other' });
2019-02-01 17:23:00 +08:00
},
2018-05-06 21:53:00 +08:00
methods: {
2019-09-28 20:45:07 +08:00
handleSubmit(e) {
2019-01-12 11:33:27 +08:00
e.preventDefault();
2018-05-06 21:53:00 +08:00
this.form.validateFields((err, values) => {
if (!err) {
2019-01-12 11:33:27 +08:00
console.log('Received values of form: ', values);
2018-05-06 21:53:00 +08:00
}
2019-01-12 11:33:27 +08:00
});
2018-05-06 21:53:00 +08:00
},
2019-09-28 20:45:07 +08:00
normFile(e) {
2019-01-12 11:33:27 +08:00
console.log('Upload event:', e);
2018-05-06 21:53:00 +08:00
if (Array.isArray(e)) {
2019-01-12 11:33:27 +08:00
return e;
2018-05-06 21:53:00 +08:00
}
2019-01-12 11:33:27 +08:00
return e && e.fileList;
2018-05-06 21:53:00 +08:00
},
},
2019-01-12 11:33:27 +08:00
};
2018-05-06 21:53:00 +08:00
</script>
<style>
#components-form-demo-validate-other .dropbox {
height: 180px;
line-height: 1.5;
}
</style>