Browse Source

BI-61057 refactor: number_editor支持自动检测范围

master
windy 4 years ago
parent
commit
ad9991020d
  1. 1
      changelog.md
  2. 30
      src/widget/numbereditor/number.editor.js

1
changelog.md

@ -1,5 +1,6 @@
# 更新日志 # 更新日志
2.0(2020-07) 2.0(2020-07)
- number_editor支持自动检测数值与范围是否合法
- 修复了颜色选择器设置值为null的时候,trigger和popup表现不一致的问题 - 修复了颜色选择器设置值为null的时候,trigger和popup表现不一致的问题
2.0(2020-06) 2.0(2020-06)

30
src/widget/numbereditor/number.editor.js

@ -6,16 +6,16 @@ BI.NumberEditor = BI.inherit(BI.Widget, {
_defaultConfig: function () { _defaultConfig: function () {
return BI.extend(BI.NumberEditor.superclass._defaultConfig.apply(this, arguments), { return BI.extend(BI.NumberEditor.superclass._defaultConfig.apply(this, arguments), {
baseCls: "bi-number-editor bi-border bi-focus-shadow", baseCls: "bi-number-editor bi-border bi-focus-shadow",
validationChecker: function () { validationChecker: BI.emptyFn,
return true;
},
valueFormatter: function (v) { valueFormatter: function (v) {
return v; return v;
}, },
value: 0, value: 0,
allowBlank: false, allowBlank: false,
errorText: "", 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, height: o.height - 2,
allowBlank: o.allowBlank, allowBlank: o.allowBlank,
value: o.valueFormatter(o.value), 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 errorText: o.errorText
}); });
this.editor.on(BI.TextEditor.EVENT_CHANGE, function () { 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 () { this.editor.on(BI.TextEditor.EVENT_ERROR, function () {
o.value = BI.parseFloat(this.getLastValidValue()); o.value = BI.parseFloat(this.getLastValidValue());
self._checkAdjustDisabled(o.value);
}); });
this.editor.on(BI.TextEditor.EVENT_VALID, function () { this.editor.on(BI.TextEditor.EVENT_VALID, function () {
o.value = BI.parseFloat(this.getValue()); o.value = BI.parseFloat(this.getValue());
self._checkAdjustDisabled(o.value);
}); });
this.editor.on(BI.TextEditor.EVENT_CONFIRM, function () { this.editor.on(BI.TextEditor.EVENT_CONFIRM, function () {
self.fireEvent(BI.NumberEditor.EVENT_CONFIRM); self.fireEvent(BI.NumberEditor.EVENT_CONFIRM);
@ -96,6 +104,18 @@ BI.NumberEditor = BI.inherit(BI.Widget, {
return this.editor.isEditing(); 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) { _finetuning: function (add) {
var v = BI.parseFloat(this.getValue()); var v = BI.parseFloat(this.getValue());

Loading…
Cancel
Save