Commit 578ca325379ffb9e7cda4fe5f3ca7486d0aa6d5f
1 parent
184dba1c
fixed Radio bug
fixed Radio bug
Showing
6 changed files
with
42 additions
and
7 deletions
Show diff stats
assets/iview.png
src/components/form/form-item.vue
... | ... | @@ -219,9 +219,8 @@ |
219 | 219 | return false; |
220 | 220 | } |
221 | 221 | }); |
222 | - // todo | |
223 | -// this.$on('el.form.blur', this.onFieldBlur); | |
224 | -// this.$on('el.form.change', this.onFieldChange); | |
222 | + this.$on('on-form-blur', this.onFieldBlur); | |
223 | + this.$on('on-form-change', this.onFieldChange); | |
225 | 224 | } |
226 | 225 | } |
227 | 226 | }, | ... | ... |
src/components/input/input.vue
... | ... | @@ -140,9 +140,11 @@ |
140 | 140 | }, |
141 | 141 | handleBlur () { |
142 | 142 | this.$emit('on-blur'); |
143 | + this.$dispatch('on-form-blur', this.value); | |
143 | 144 | }, |
144 | 145 | handleChange (event) { |
145 | 146 | this.$emit('on-change', event); |
147 | + this.$dispatch('on-form-change', this.value); | |
146 | 148 | }, |
147 | 149 | resizeTextarea () { |
148 | 150 | const autosize = this.autosize; | ... | ... |
src/components/radio/radio-group.vue
... | ... | @@ -9,6 +9,7 @@ |
9 | 9 | const prefixCls = 'ivu-radio-group'; |
10 | 10 | |
11 | 11 | export default { |
12 | + name: 'radioGroup', | |
12 | 13 | props: { |
13 | 14 | model: { |
14 | 15 | type: [String, Number], |
... | ... | @@ -51,6 +52,7 @@ |
51 | 52 | this.model = data.value; |
52 | 53 | this.updateModel(); |
53 | 54 | this.$emit('on-change', data.value); |
55 | + this.$dispatch('on-form-change', data.value); | |
54 | 56 | } |
55 | 57 | }, |
56 | 58 | watch: { | ... | ... |
src/components/radio/radio.vue
... | ... | @@ -62,6 +62,7 @@ |
62 | 62 | } |
63 | 63 | }, |
64 | 64 | ready () { |
65 | + if (this.$parent && this.$parent.$options.name === 'radioGroup') this.group = true; | |
65 | 66 | if (!this.group) { |
66 | 67 | this.updateModel(); |
67 | 68 | } |
... | ... | @@ -81,6 +82,8 @@ |
81 | 82 | checked: this.checked |
82 | 83 | }); |
83 | 84 | } |
85 | + | |
86 | + if (!this.group) this.$dispatch('on-form-change', this.selected); | |
84 | 87 | }, |
85 | 88 | updateModel () { |
86 | 89 | this.selected = this.checked; | ... | ... |
test/routers/form.vue
1 | 1 | <template> |
2 | 2 | <div style="width: 400px"> |
3 | - <i-form v-ref:form :model="form" :rules="rules" :label-width="50" label-position="right"> | |
3 | + <i-form v-ref:form :model="form" :rules="rules" :label-width="100" label-position="right"> | |
4 | 4 | <form-item label="邮箱" prop="mail"> |
5 | 5 | <i-input :value.sync="form.mail" placeholder="请输入邮箱"> |
6 | 6 | <Icon type="ios-email-outline" slot="prepend"></Icon> |
... | ... | @@ -11,6 +11,25 @@ |
11 | 11 | <Icon type="ios-locked-outline" slot="prepend"></Icon> |
12 | 12 | </i-input> |
13 | 13 | </form-item> |
14 | + <form-item label="radio" prop="single"> | |
15 | + <radio :checked.sync="form.single">Single</radio> | |
16 | + </form-item> | |
17 | + <form-item label="radioGroup" prop="group"> | |
18 | + <Radio-group :model.sync="form.group"> | |
19 | + <Radio value="apple"> | |
20 | + <Icon type="social-apple"></Icon> | |
21 | + <span>Apple</span> | |
22 | + </Radio> | |
23 | + <Radio value="android"> | |
24 | + <Icon type="social-android"></Icon> | |
25 | + <span>Android</span> | |
26 | + </Radio> | |
27 | + <Radio value="windows"> | |
28 | + <Icon type="social-windows"></Icon> | |
29 | + <span>Windows</span> | |
30 | + </Radio> | |
31 | + </Radio-group> | |
32 | + </form-item> | |
14 | 33 | <form-item> |
15 | 34 | <i-button type="primary" @click="onSubmit('form')">提交</i-button> |
16 | 35 | </form-item> |
... | ... | @@ -24,21 +43,31 @@ |
24 | 43 | return { |
25 | 44 | form: { |
26 | 45 | mail: '', |
27 | - passwd: '' | |
46 | + passwd: '', | |
47 | + single: false, | |
48 | + group: '' | |
28 | 49 | }, |
29 | 50 | rules: { |
30 | 51 | mail: [ |
31 | 52 | { |
32 | - required: true, message: '请输入邮箱', trigger: 'blur' | |
53 | + required: true, message: '请输入正确的邮箱', trigger: 'blur', type: 'email' | |
54 | + }, | |
55 | + { | |
56 | + min: 3, max: 50, message: '长度在 3 到 50 个字符', trigger: 'blur' | |
33 | 57 | }, |
34 | 58 | { |
35 | - min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' | |
59 | + min: 3, max: 50, message: '长度在 3 到 5 个字符', trigger: 'change' | |
36 | 60 | } |
37 | 61 | ], |
38 | 62 | passwd: [ |
39 | 63 | { |
40 | 64 | required: true, message: '请输入密码', trigger: 'blur' |
41 | 65 | } |
66 | + ], | |
67 | + group: [ | |
68 | + { | |
69 | + required: true, message: '请单选组' | |
70 | + } | |
42 | 71 | ] |
43 | 72 | } |
44 | 73 | } | ... | ... |