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 34 </div>
35 35 </template>
36 36 <script>
37   - import { oneOf } from '../../utils/assist';
  37 + import { oneOf, findComponentUpward } from '../../utils/assist';
38 38 import Emitter from '../../mixins/emitter';
39 39  
40 40 const prefixCls = 'ivu-input-number';
... ... @@ -254,16 +254,16 @@
254 254 setValue (val) {
255 255 // 如果 step 是小数,且没有设置 precision,是有问题的
256 256 if (val && !isNaN(this.precision)) val = Number(Number(val).toFixed(this.precision));
257   -
  257 +
258 258 const {min, max} = this;
259 259 if (val!==null) {
260 260 if (val > max) {
261 261 val = max;
262 262 } else if (val < min) {
263 263 val = min;
264   - }
  264 + }
265 265 }
266   -
  266 +
267 267 this.$nextTick(() => {
268 268 this.currentValue = val;
269 269 this.$emit('input', val);
... ... @@ -278,6 +278,9 @@
278 278 blur () {
279 279 this.focused = false;
280 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 285 keyDown (e) {
283 286 if (e.keyCode === 38) {
... ... @@ -289,20 +292,20 @@
289 292 }
290 293 },
291 294 change (event) {
292   -
293   - if (event.type == 'input' && !this.activeChange) return;
  295 +
  296 + if (event.type == 'input' && !this.activeChange) return;
294 297 let val = event.target.value.trim();
295 298 if (this.parser) {
296 299 val = this.parser(val);
297 300 }
298   -
  301 +
299 302 const isEmptyString = val.length === 0;
300 303 if(isEmptyString){
301 304 this.setValue(null);
302 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 309 val = Number(val);
307 310  
308 311 if (!isNaN(val)) {
... ...