diff --git a/changelog.md b/changelog.md index 0487670a2f..88bac7e891 100644 --- a/changelog.md +++ b/changelog.md @@ -1,6 +1,7 @@ # 更新日志 2.0(2020-07) - 复选下拉树和下拉列表添加showView和hideVIew方法 +- number_editor支持自动检测数值与范围是否合法 - 修复了颜色选择器设置值为null的时候,trigger和popup表现不一致的问题 2.0(2020-06) diff --git a/src/widget/numbereditor/number.editor.js b/src/widget/numbereditor/number.editor.js index 05292867d4..c68cba4c20 100644 --- a/src/widget/numbereditor/number.editor.js +++ b/src/widget/numbereditor/number.editor.js @@ -6,16 +6,16 @@ BI.NumberEditor = BI.inherit(BI.Widget, { _defaultConfig: function () { return BI.extend(BI.NumberEditor.superclass._defaultConfig.apply(this, arguments), { baseCls: "bi-number-editor bi-border bi-focus-shadow", - validationChecker: function () { - return true; - }, + validationChecker: BI.emptyFn, valueFormatter: function (v) { return v; }, value: 0, allowBlank: false, errorText: "", - step: 1 + step: 1, + min: BI.MIN, + max: BI.MAX }); }, @@ -27,7 +27,13 @@ BI.NumberEditor = BI.inherit(BI.Widget, { height: o.height - 2, allowBlank: o.allowBlank, value: o.valueFormatter(o.value), - validationChecker: o.validationChecker, + validationChecker: function (v) { + // 不设置validationChecker就自动检测 + if(o.validationChecker === BI.emptyFn && !self._checkValueInRange(v)) { + return false; + } + return o.validationChecker(v); + }, errorText: o.errorText }); this.editor.on(BI.TextEditor.EVENT_CHANGE, function () { @@ -35,9 +41,11 @@ BI.NumberEditor = BI.inherit(BI.Widget, { }); this.editor.on(BI.TextEditor.EVENT_ERROR, function () { o.value = BI.parseFloat(this.getLastValidValue()); + self._checkAdjustDisabled(o.value); }); this.editor.on(BI.TextEditor.EVENT_VALID, function () { o.value = BI.parseFloat(this.getValue()); + self._checkAdjustDisabled(o.value); }); this.editor.on(BI.TextEditor.EVENT_CONFIRM, function () { self.fireEvent(BI.NumberEditor.EVENT_CONFIRM); @@ -96,6 +104,18 @@ BI.NumberEditor = BI.inherit(BI.Widget, { return this.editor.isEditing(); }, + _checkValueInRange: function(v) { + var o = this.options; + return !!(BI.isNumeric(v) && BI.parseFloat(v) >= o.min && BI.parseFloat(v) <= o.max); + }, + + _checkAdjustDisabled: function(v) { + if(this.options.validationChecker === BI.emptyFn) { + this.bottomBtn.setEnable(BI.parseFloat(v) > this.options.min); + this.topBtn.setEnable(BI.parseFloat(v) < this.options.max); + } + }, + // 微调 _finetuning: function (add) { var v = BI.parseFloat(this.getValue());