From ad9991020d83cce9e9ef2c8dab3b42a52c977af7 Mon Sep 17 00:00:00 2001 From: windy <1374721899@qq.com> Date: Fri, 3 Jul 2020 09:57:40 +0800 Subject: [PATCH] =?UTF-8?q?BI-61057=20refactor:=20number=5Feditor=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E8=87=AA=E5=8A=A8=E6=A3=80=E6=B5=8B=E8=8C=83=E5=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- changelog.md | 1 + src/widget/numbereditor/number.editor.js | 30 ++++++++++++++++++++---- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/changelog.md b/changelog.md index 67fbc34c6a..97d0ec1feb 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,6 @@ # 更新日志 2.0(2020-07) +- 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());