|
|
|
@ -7,12 +7,13 @@
|
|
|
|
|
BI.Input = BI.inherit(BI.Single, { |
|
|
|
|
_defaultConfig: function () { |
|
|
|
|
var conf = BI.Input.superclass._defaultConfig.apply(this, arguments); |
|
|
|
|
|
|
|
|
|
return BI.extend(conf, { |
|
|
|
|
baseCls: (conf.baseCls || "") + " bi-input display-block overflow-dot", |
|
|
|
|
tagName: "input", |
|
|
|
|
validationChecker: BI.emptyFn, |
|
|
|
|
quitChecker: BI.emptyFn, // 按确定键能否退出编辑
|
|
|
|
|
allowBlank: false |
|
|
|
|
allowBlank: false, |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
@ -27,15 +28,15 @@ BI.Input = BI.inherit(BI.Single, {
|
|
|
|
|
}, BI.EVENT_RESPONSE_TIME); |
|
|
|
|
var _clk = BI.debounce(BI.bind(this._click, this), BI.EVENT_RESPONSE_TIME, { |
|
|
|
|
"leading": true, |
|
|
|
|
"trailing": false |
|
|
|
|
"trailing": false, |
|
|
|
|
}); |
|
|
|
|
this._focusDebounce = BI.debounce(BI.bind(this._focus, this), BI.EVENT_RESPONSE_TIME, { |
|
|
|
|
"leading": true, |
|
|
|
|
"trailing": false |
|
|
|
|
"trailing": false, |
|
|
|
|
}); |
|
|
|
|
this._blurDebounce = BI.debounce(BI.bind(this._blur, this), BI.EVENT_RESPONSE_TIME, { |
|
|
|
|
"leading": true, |
|
|
|
|
"trailing": false |
|
|
|
|
"trailing": false, |
|
|
|
|
}); |
|
|
|
|
this.element |
|
|
|
|
.keydown(function (e) { |
|
|
|
@ -86,7 +87,7 @@ BI.Input = BI.inherit(BI.Single, {
|
|
|
|
|
this.element.addClass("bi-input-focus"); |
|
|
|
|
this._checkValidationOnValueChange(); |
|
|
|
|
this._isEditing = true; |
|
|
|
|
if (this.getValue() == "") { |
|
|
|
|
if (this.getValue() === "") { |
|
|
|
|
this.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.EMPTY, this.getValue(), this); |
|
|
|
|
this.fireEvent(BI.Input.EVENT_EMPTY); |
|
|
|
|
} |
|
|
|
@ -139,7 +140,7 @@ BI.Input = BI.inherit(BI.Single, {
|
|
|
|
|
this._checkValidationOnValueChange(); |
|
|
|
|
} |
|
|
|
|
if (this.isValid() && BI.trim(this.getValue()) !== "") { |
|
|
|
|
if (BI.trim(this.getValue()) !== this._lastValue && (!this._start || this._lastValue == null || this._lastValue === "") |
|
|
|
|
if (BI.trim(this.getValue()) !== this._lastValue && (!this._start || BI.isNull(this._lastValue) || this._lastValue === "") |
|
|
|
|
|| (this._pause === true && !/(\s|\u00A0)$/.test(this.getValue()))) { |
|
|
|
|
this._start = true; |
|
|
|
|
this._pause = false; |
|
|
|
@ -147,7 +148,7 @@ BI.Input = BI.inherit(BI.Single, {
|
|
|
|
|
this.fireEvent(BI.Input.EVENT_START); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (keyCode == BI.KeyCode.ENTER) { |
|
|
|
|
if (BI.isEqual(keyCode, BI.KeyCode.ENTER)) { |
|
|
|
|
if (this.isValid() || this.options.quitChecker.apply(this, [BI.trim(this.getValue())]) !== false) { |
|
|
|
|
this.blur(); |
|
|
|
|
this.fireEvent(BI.Input.EVENT_ENTER); |
|
|
|
@ -155,20 +156,20 @@ BI.Input = BI.inherit(BI.Single, {
|
|
|
|
|
this.fireEvent(BI.Input.EVENT_RESTRICT); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (keyCode == BI.KeyCode.SPACE) { |
|
|
|
|
if (BI.isEqual(keyCode, BI.KeyCode.SPACE)) { |
|
|
|
|
this.fireEvent(BI.Input.EVENT_SPACE); |
|
|
|
|
} |
|
|
|
|
if (keyCode == BI.KeyCode.BACKSPACE && this._lastValue == "") { |
|
|
|
|
if (BI.isEqual(keyCode, BI.KeyCode.BACKSPACE) && this._lastValue === "") { |
|
|
|
|
this.fireEvent(BI.Input.EVENT_REMOVE); |
|
|
|
|
} |
|
|
|
|
if (keyCode == BI.KeyCode.BACKSPACE || keyCode == BI.KeyCode.DELETE) { |
|
|
|
|
if (BI.isEqual(keyCode, BI.KeyCode.BACKSPACE) || BI.isEqual(keyCode, BI.KeyCode.DELETE)) { |
|
|
|
|
this.fireEvent(BI.Input.EVENT_BACKSPACE); |
|
|
|
|
} |
|
|
|
|
this.fireEvent(BI.Input.EVENT_KEY_DOWN, arguments); |
|
|
|
|
|
|
|
|
|
// _valueChange中会更新_lastValue, 这边缓存用以后续STOP事件服务
|
|
|
|
|
var lastValue = this._lastValue; |
|
|
|
|
if(BI.trim(this.getValue()) !== BI.trim(this._lastValue || "")){ |
|
|
|
|
if (BI.trim(this.getValue()) !== BI.trim(this._lastValue || "")) { |
|
|
|
|
this._valueChange(); |
|
|
|
|
} |
|
|
|
|
if (BI.isEndWithBlank(this.getValue())) { |
|
|
|
@ -185,7 +186,7 @@ BI.Input = BI.inherit(BI.Single, {
|
|
|
|
|
|
|
|
|
|
// 初始状态
|
|
|
|
|
_defaultState: function () { |
|
|
|
|
if (this.getValue() == "") { |
|
|
|
|
if (this.getValue() === "") { |
|
|
|
|
this.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.EMPTY, this.getValue(), this); |
|
|
|
|
this.fireEvent(BI.Input.EVENT_EMPTY); |
|
|
|
|
} |
|
|
|
@ -199,7 +200,7 @@ BI.Input = BI.inherit(BI.Single, {
|
|
|
|
|
this.fireEvent(BI.Input.EVENT_CHANGE); |
|
|
|
|
this._lastSubmitValue = BI.trim(this.getValue()); |
|
|
|
|
} |
|
|
|
|
if (this.getValue() == "") { |
|
|
|
|
if (this.getValue() === "") { |
|
|
|
|
this.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.EMPTY, this.getValue(), this); |
|
|
|
|
this.fireEvent(BI.Input.EVENT_EMPTY); |
|
|
|
|
} |
|
|
|
@ -209,14 +210,16 @@ BI.Input = BI.inherit(BI.Single, {
|
|
|
|
|
_checkValidationOnValueChange: function (callback) { |
|
|
|
|
var self = this, o = this.options; |
|
|
|
|
var v = this.getValue(); |
|
|
|
|
if (o.allowBlank === true && BI.trim(v) == "") { |
|
|
|
|
if (o.allowBlank === true && BI.trim(v) === "") { |
|
|
|
|
this.setValid(true); |
|
|
|
|
callback && callback(); |
|
|
|
|
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (BI.trim(v) == "") { |
|
|
|
|
if (BI.trim(v) === "") { |
|
|
|
|
this.setValid(false); |
|
|
|
|
callback && callback(); |
|
|
|
|
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
var checker = o.validationChecker.apply(this, [BI.trim(v)]); |
|
|
|
@ -224,7 +227,7 @@ BI.Input = BI.inherit(BI.Single, {
|
|
|
|
|
checker.then(function (validate) { |
|
|
|
|
self.setValid(validate !== false); |
|
|
|
|
callback && callback(); |
|
|
|
|
}) |
|
|
|
|
}); |
|
|
|
|
} else { |
|
|
|
|
this.setValid(checker !== false); |
|
|
|
|
callback && callback(); |
|
|
|
@ -306,7 +309,7 @@ BI.Input = BI.inherit(BI.Single, {
|
|
|
|
|
_setEnable: function (b) { |
|
|
|
|
BI.Input.superclass._setEnable.apply(this, [b]); |
|
|
|
|
this.element[0].disabled = !b; |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
}); |
|
|
|
|
BI.Input.EVENT_CHANGE = "EVENT_CHANGE"; |
|
|
|
|
|
|
|
|
|