Commit 0941fdc0be62f92db3be65290c55596d5ea9095e

Authored by Aresn
Committed by GitHub
2 parents 65ac50a0 42589ae3

Merge pull request #4536 from weidapao/fix_bug

 fix(InputNumber): 解决组件InputNumber无法blur时校验的问题
Showing 1 changed file with 12 additions and 9 deletions   Show diff stats
src/components/input-number/input-number.vue
@@ -34,7 +34,7 @@ @@ -34,7 +34,7 @@
34 </div> 34 </div>
35 </template> 35 </template>
36 <script> 36 <script>
37 - import { oneOf } from '../../utils/assist'; 37 + import { oneOf, findComponentUpward } from '../../utils/assist';
38 import Emitter from '../../mixins/emitter'; 38 import Emitter from '../../mixins/emitter';
39 39
40 const prefixCls = 'ivu-input-number'; 40 const prefixCls = 'ivu-input-number';
@@ -254,16 +254,16 @@ @@ -254,16 +254,16 @@
254 setValue (val) { 254 setValue (val) {
255 // 如果 step 是小数,且没有设置 precision,是有问题的 255 // 如果 step 是小数,且没有设置 precision,是有问题的
256 if (val && !isNaN(this.precision)) val = Number(Number(val).toFixed(this.precision)); 256 if (val && !isNaN(this.precision)) val = Number(Number(val).toFixed(this.precision));
257 - 257 +
258 const {min, max} = this; 258 const {min, max} = this;
259 if (val!==null) { 259 if (val!==null) {
260 if (val > max) { 260 if (val > max) {
261 val = max; 261 val = max;
262 } else if (val < min) { 262 } else if (val < min) {
263 val = min; 263 val = min;
264 - } 264 + }
265 } 265 }
266 - 266 +
267 this.$nextTick(() => { 267 this.$nextTick(() => {
268 this.currentValue = val; 268 this.currentValue = val;
269 this.$emit('input', val); 269 this.$emit('input', val);
@@ -278,6 +278,9 @@ @@ -278,6 +278,9 @@
278 blur () { 278 blur () {
279 this.focused = false; 279 this.focused = false;
280 this.$emit('on-blur'); 280 this.$emit('on-blur');
  281 + if (!findComponentUpward(this, ['DatePicker', 'TimePicker', 'Cascader', 'Search'])) {
  282 + this.dispatch('FormItem', 'on-form-blur', this.currentValue);
  283 + }
281 }, 284 },
282 keyDown (e) { 285 keyDown (e) {
283 if (e.keyCode === 38) { 286 if (e.keyCode === 38) {
@@ -289,20 +292,20 @@ @@ -289,20 +292,20 @@
289 } 292 }
290 }, 293 },
291 change (event) { 294 change (event) {
292 -  
293 - if (event.type == 'input' && !this.activeChange) return; 295 +
  296 + if (event.type == 'input' && !this.activeChange) return;
294 let val = event.target.value.trim(); 297 let val = event.target.value.trim();
295 if (this.parser) { 298 if (this.parser) {
296 val = this.parser(val); 299 val = this.parser(val);
297 } 300 }
298 - 301 +
299 const isEmptyString = val.length === 0; 302 const isEmptyString = val.length === 0;
300 if(isEmptyString){ 303 if(isEmptyString){
301 this.setValue(null); 304 this.setValue(null);
302 return; 305 return;
303 } 306 }
304 - if (event.type == 'input' && val.match(/^\-?\.?$|\.$/)) return; // prevent fire early if decimal. If no more input the change event will fire later  
305 - 307 + if (event.type == 'input' && val.match(/^\-?\.?$|\.$/)) return; // prevent fire early if decimal. If no more input the change event will fire later
  308 +
306 val = Number(val); 309 val = Number(val);
307 310
308 if (!isNaN(val)) { 311 if (!isNaN(val)) {