Commit 21dad188c11ae33e6cb4a940a5ea1ae01b23fee2
1 parent
4a5d5cc9
prevent dispatch form event
when component import an Input, prevent dispatch event from Input to Form
Showing
8 changed files
with
92 additions
and
54 deletions
Show diff stats
examples/routers/form.vue
1 | 1 | <template> |
2 | - <i-form ref="formInline" :model="formInline" :rules="ruleInline" inline> | |
3 | - <Form-item prop="user"> | |
4 | - <Input type="text" v-model="formInline.user" placeholder="Username"> | |
5 | - <Icon type="ios-person-outline" slot="prepend"></Icon> | |
6 | - </Input> | |
7 | - </Form-item> | |
8 | - <Form-item prop="password"> | |
9 | - <Input type="password" v-model="formInline.password" placeholder="Password"> | |
10 | - <Icon type="ios-locked-outline" slot="prepend"></Icon> | |
11 | - </Input> | |
12 | - </Form-item> | |
13 | - <Form-item> | |
14 | - <Button type="primary" @click.native="handleSubmit('formInline')">登录</Button> | |
15 | - </Form-item> | |
16 | - </i-form> | |
2 | + <div> | |
3 | + date: {{ formInline.date }} | |
4 | + <i-form ref="formInline" :model="formInline" :rules="ruleInline"> | |
5 | + <Form-item prop="date"> | |
6 | + <Date-picker type="date" placeholder="选择日期" v-model="formInline.date"></Date-picker> | |
7 | + </Form-item> | |
8 | + <Form-item prop="user"> | |
9 | + <Input v-model="formInline.user"> | |
10 | + </Form-item> | |
11 | + <Form-item> | |
12 | + <i-button type="primary" @click.native="handleSubmit('formInline')">登录</i-button> | |
13 | + </Form-item> | |
14 | + </i-form> | |
15 | + </div> | |
17 | 16 | </template> |
18 | 17 | <script> |
19 | 18 | export default { |
20 | 19 | data () { |
21 | 20 | return { |
22 | 21 | formInline: { |
23 | - user: '', | |
24 | - password: '' | |
22 | + date: new Date(), | |
23 | + user: '' | |
25 | 24 | }, |
26 | 25 | ruleInline: { |
27 | - user: [ | |
28 | - { required: true, message: '请填写用户名', trigger: 'blur' } | |
26 | + date: [ | |
27 | + { | |
28 | + required: true, | |
29 | + type: 'date', | |
30 | + message: '请选择日期', | |
31 | + trigger: 'change' | |
32 | + } | |
29 | 33 | ], |
30 | - password: [ | |
31 | - { required: true, message: '请填写密码', trigger: 'blur' }, | |
32 | - { type: 'string', min: 6, message: '密码长度不能小于6位', trigger: 'blur' } | |
34 | + user: [ | |
35 | + { | |
36 | + required: true, | |
37 | + message: '请输入', | |
38 | + trigger: 'change', | |
39 | + min: 10 | |
40 | + }, | |
41 | + { | |
42 | + required: true, | |
43 | + message: '请输入2', | |
44 | + trigger: 'blur' | |
45 | + } | |
33 | 46 | ] |
34 | 47 | } |
35 | 48 | } |
... | ... | @@ -38,11 +51,14 @@ |
38 | 51 | handleSubmit(name) { |
39 | 52 | this.$refs[name].validate((valid) => { |
40 | 53 | if (valid) { |
41 | - console.log('success'); | |
54 | + this.$Message.success('提交成功!'); | |
42 | 55 | } else { |
43 | - console.log('fail') | |
56 | + this.$Message.error('表单验证失败!'); | |
44 | 57 | } |
45 | 58 | }) |
59 | + }, | |
60 | + handleInput (val) { | |
61 | + console.log(val) | |
46 | 62 | } |
47 | 63 | } |
48 | 64 | } | ... | ... |
examples/routers/message.vue
1 | 1 | <template> |
2 | - <i-button @click.native="time">显示一个10秒的提示</i-button> | |
2 | + <div> | |
3 | + <i-button @click.native="success">显示成功提示</i-button> | |
4 | + <i-button @click.native="warning">显示警告提示</i-button> | |
5 | + <i-button @click.native="error">显示错误提示</i-button> | |
6 | + </div> | |
3 | 7 | </template> |
4 | 8 | <script> |
5 | 9 | export default { |
6 | 10 | methods: { |
7 | - time () { | |
8 | - this.$Message.info('我将在10秒后消失', 3, () => { | |
9 | - console.log(1111) | |
10 | - }); | |
11 | + success () { | |
12 | + this.$Message.success('这是一条成功的提示'); | |
13 | + }, | |
14 | + warning () { | |
15 | + this.$Message.warning('这是一条警告的提示'); | |
16 | + }, | |
17 | + error () { | |
18 | + this.$Message.error('对方不想说话,并且向你抛出了一个异常'); | |
11 | 19 | } |
12 | - }, | |
13 | - mounted () { | |
14 | - this.$Message.config({ | |
15 | - top: 50, | |
16 | - duration: 3 | |
17 | - }); | |
18 | 20 | } |
19 | 21 | } |
20 | 22 | </script> | ... | ... |
src/components/base/notification/notification.vue
... | ... | @@ -2,7 +2,7 @@ |
2 | 2 | <div :class="classes" :style="styles"> |
3 | 3 | <Notice |
4 | 4 | v-for="notice in notices" |
5 | - :key="notice" | |
5 | + :key="notice.name" | |
6 | 6 | :prefix-cls="prefixCls" |
7 | 7 | :styles="notice.styles" |
8 | 8 | :content="notice.content" |
... | ... | @@ -15,7 +15,6 @@ |
15 | 15 | </div> |
16 | 16 | </template> |
17 | 17 | <script> |
18 | - // todo :key="notice" | |
19 | 18 | import Notice from './notice.vue'; |
20 | 19 | |
21 | 20 | const prefixCls = 'ivu-notification'; | ... | ... |
src/components/date-picker/panel/time-range.vue
src/components/date-picker/panel/time.vue
src/components/date-picker/picker.vue
... | ... | @@ -139,6 +139,7 @@ |
139 | 139 | }; |
140 | 140 | |
141 | 141 | export default { |
142 | + name: 'CalendarPicker', | |
142 | 143 | mixins: [ Emitter ], |
143 | 144 | components: { iInput, Drop }, |
144 | 145 | directives: { clickoutside }, |
... | ... | @@ -344,6 +345,7 @@ |
344 | 345 | this.visualValue = correctValue; |
345 | 346 | event.target.value = correctValue; |
346 | 347 | this.internalValue = correctDate; |
348 | + this.currentValue = correctDate; | |
347 | 349 | |
348 | 350 | if (correctValue !== oldValue) this.emitChange(correctDate); |
349 | 351 | }, |
... | ... | @@ -418,6 +420,12 @@ |
418 | 420 | this.picker.resetView && this.picker.resetView(); |
419 | 421 | }, |
420 | 422 | emitChange (date) { |
423 | + const newDate = this.formattingDate(date); | |
424 | + | |
425 | + this.$emit('on-change', newDate); | |
426 | + this.dispatch('FormItem', 'on-form-change', newDate); | |
427 | + }, | |
428 | + formattingDate (date) { | |
421 | 429 | const type = this.type; |
422 | 430 | const format = this.format || DEFAULT_FORMATS[type]; |
423 | 431 | const formatter = ( |
... | ... | @@ -429,9 +437,7 @@ |
429 | 437 | if (type === 'daterange' || type === 'timerange') { |
430 | 438 | newDate = [newDate.split(RANGE_SEPARATOR)[0], newDate.split(RANGE_SEPARATOR)[1]]; |
431 | 439 | } |
432 | - | |
433 | - this.$emit('on-change', newDate); | |
434 | - this.dispatch('FormItem', 'on-form-change', newDate); | |
440 | + return newDate; | |
435 | 441 | } |
436 | 442 | }, |
437 | 443 | watch: { |
... | ... | @@ -450,7 +456,7 @@ |
450 | 456 | if (!val && this.picker && typeof this.picker.handleClear === 'function') { |
451 | 457 | this.picker.handleClear(); |
452 | 458 | } |
453 | - this.$emit('input', val); | |
459 | +// this.$emit('input', val); | |
454 | 460 | }, |
455 | 461 | value (val) { |
456 | 462 | this.currentValue = val; |
... | ... | @@ -492,14 +498,5 @@ |
492 | 498 | mounted () { |
493 | 499 | if (this.open !== null) this.visible = this.open; |
494 | 500 | } |
495 | - // todo 事件 | |
496 | -// events: { | |
497 | -// 'on-form-blur' () { | |
498 | -// return false; | |
499 | -// }, | |
500 | -// 'on-form-change' () { | |
501 | -// return false; | |
502 | -// } | |
503 | -// } | |
504 | 501 | }; |
505 | 502 | </script> | ... | ... |
src/components/input/input.vue
... | ... | @@ -43,7 +43,7 @@ |
43 | 43 | </div> |
44 | 44 | </template> |
45 | 45 | <script> |
46 | - import { oneOf } from '../../utils/assist'; | |
46 | + import { oneOf, findComponentUpward } from '../../utils/assist'; | |
47 | 47 | import calcTextareaHeight from '../../utils/calcTextareaHeight'; |
48 | 48 | import Emitter from '../../mixins/emitter'; |
49 | 49 | |
... | ... | @@ -152,7 +152,9 @@ |
152 | 152 | }, |
153 | 153 | handleBlur () { |
154 | 154 | this.$emit('on-blur'); |
155 | - this.dispatch('FormItem', 'on-form-blur', this.currentValue); | |
155 | + if (!findComponentUpward(this, ['DatePicker', 'TimePicker'])) { | |
156 | + this.dispatch('FormItem', 'on-form-blur', this.currentValue); | |
157 | + } | |
156 | 158 | }, |
157 | 159 | handleInput (event) { |
158 | 160 | const value = event.target.value; |
... | ... | @@ -169,7 +171,9 @@ |
169 | 171 | this.resizeTextarea(); |
170 | 172 | }); |
171 | 173 | this.currentValue = value; |
172 | - this.dispatch('FormItem', 'on-form-change', value); | |
174 | + if (!findComponentUpward(this, ['DatePicker', 'TimePicker'])) { | |
175 | + this.dispatch('FormItem', 'on-form-change', value); | |
176 | + } | |
173 | 177 | }, |
174 | 178 | resizeTextarea () { |
175 | 179 | const autosize = this.autosize; | ... | ... |
src/utils/assist.js
... | ... | @@ -165,4 +165,22 @@ export function scrollTop(el, from = 0, to, duration = 500) { |
165 | 165 | window.requestAnimationFrame(() => scroll(d, end, step)); |
166 | 166 | } |
167 | 167 | scroll(from, to, step); |
168 | -} | |
169 | 168 | \ No newline at end of file |
169 | +} | |
170 | + | |
171 | +// Find components upward | |
172 | +function findComponentUpward (content, componentName, componentNames) { | |
173 | + if (typeof componentName === 'string') { | |
174 | + componentNames = [componentName]; | |
175 | + } else { | |
176 | + componentNames = componentName; | |
177 | + } | |
178 | + | |
179 | + let parent = content.$parent; | |
180 | + let name = parent.$options.name; | |
181 | + while (parent && (!name || componentNames.indexOf(name) < 0)) { | |
182 | + parent = parent.$parent; | |
183 | + if (parent) name = parent.$options.name; | |
184 | + } | |
185 | + return parent; | |
186 | +} | |
187 | +export {findComponentUpward}; | |
170 | 188 | \ No newline at end of file | ... | ... |