mirror of https://github.com/ElemeFE/element
				
				
				
			Select: fix form change validation (#11672)
							parent
							
								
									1f24f2abae
								
							
						
					
					
						commit
						0ed8d18603
					
				|  | @ -339,7 +339,7 @@ | ||||||
|         this.cachedPlaceHolder = this.currentPlaceholder = val; |         this.cachedPlaceHolder = this.currentPlaceholder = val; | ||||||
|       }, |       }, | ||||||
| 
 | 
 | ||||||
|       value(val) { |       value(val, oldVal) { | ||||||
|         if (this.multiple) { |         if (this.multiple) { | ||||||
|           this.resetInputHeight(); |           this.resetInputHeight(); | ||||||
|           if (val.length > 0 || (this.$refs.input && this.query !== '')) { |           if (val.length > 0 || (this.$refs.input && this.query !== '')) { | ||||||
|  | @ -356,6 +356,9 @@ | ||||||
|         if (this.filterable && !this.multiple) { |         if (this.filterable && !this.multiple) { | ||||||
|           this.inputLength = 20; |           this.inputLength = 20; | ||||||
|         } |         } | ||||||
|  |         if (!valueEquals(val, oldVal)) { | ||||||
|  |           this.dispatch('ElFormItem', 'el.form.change', val); | ||||||
|  |         } | ||||||
|       }, |       }, | ||||||
| 
 | 
 | ||||||
|       visible(val) { |       visible(val) { | ||||||
|  | @ -503,7 +506,6 @@ | ||||||
|       emitChange(val) { |       emitChange(val) { | ||||||
|         if (!valueEquals(this.value, val)) { |         if (!valueEquals(this.value, val)) { | ||||||
|           this.$emit('change', val); |           this.$emit('change', val); | ||||||
|           this.dispatch('ElFormItem', 'el.form.change', val); |  | ||||||
|         } |         } | ||||||
|       }, |       }, | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -380,15 +380,19 @@ describe('Form', () => { | ||||||
|         expect(valid).to.false; |         expect(valid).to.false; | ||||||
|         setTimeout(_ => { |         setTimeout(_ => { | ||||||
|           expect(field.validateMessage).to.equal('请选择活动区域'); |           expect(field.validateMessage).to.equal('请选择活动区域'); | ||||||
|           // programatic modification of bound value does not triggers change validation |           // programatic modification triggers change validation | ||||||
|           vm.form.region = 'shanghai'; |           vm.form.region = 'shanghai'; | ||||||
|           setTimeout(_ => { |           setTimeout(_ => { | ||||||
|             expect(field.validateMessage).to.equal('请选择活动区域'); |             expect(field.validateMessage).to.equal(''); | ||||||
|             // user modification of bound value triggers change validation |             vm.form.region = ''; | ||||||
|             vm.$refs.opt.$el.click(); |  | ||||||
|             setTimeout(_ => { |             setTimeout(_ => { | ||||||
|               expect(field.validateMessage).to.equal(''); |               expect(field.validateMessage).to.equal('请选择活动区域'); | ||||||
|               done(); |               // user modification of bound value triggers change validation | ||||||
|  |               vm.$refs.opt.$el.click(); | ||||||
|  |               setTimeout(_ => { | ||||||
|  |                 expect(field.validateMessage).to.equal(''); | ||||||
|  |                 done(); | ||||||
|  |               }, 100); | ||||||
|             }, 100); |             }, 100); | ||||||
|           }, 100); |           }, 100); | ||||||
|         }, 100); |         }, 100); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 Jiewei Qian
						Jiewei Qian