|
|
@ -7,12 +7,13 @@ |
|
|
|
BI.Input = BI.inherit(BI.Single, { |
|
|
|
BI.Input = BI.inherit(BI.Single, { |
|
|
|
_defaultConfig: function () { |
|
|
|
_defaultConfig: function () { |
|
|
|
var conf = BI.Input.superclass._defaultConfig.apply(this, arguments); |
|
|
|
var conf = BI.Input.superclass._defaultConfig.apply(this, arguments); |
|
|
|
|
|
|
|
|
|
|
|
return BI.extend(conf, { |
|
|
|
return BI.extend(conf, { |
|
|
|
baseCls: (conf.baseCls || "") + " bi-input display-block overflow-dot", |
|
|
|
baseCls: (conf.baseCls || "") + " bi-input display-block overflow-dot", |
|
|
|
tagName: "input", |
|
|
|
tagName: "input", |
|
|
|
validationChecker: BI.emptyFn, |
|
|
|
validationChecker: BI.emptyFn, |
|
|
|
quitChecker: BI.emptyFn, // 按确定键能否退出编辑
|
|
|
|
quitChecker: BI.emptyFn, // 按确定键能否退出编辑
|
|
|
|
allowBlank: false |
|
|
|
allowBlank: false, |
|
|
|
}); |
|
|
|
}); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
@ -27,15 +28,15 @@ BI.Input = BI.inherit(BI.Single, { |
|
|
|
}, BI.EVENT_RESPONSE_TIME); |
|
|
|
}, BI.EVENT_RESPONSE_TIME); |
|
|
|
var _clk = BI.debounce(BI.bind(this._click, this), BI.EVENT_RESPONSE_TIME, { |
|
|
|
var _clk = BI.debounce(BI.bind(this._click, this), BI.EVENT_RESPONSE_TIME, { |
|
|
|
"leading": true, |
|
|
|
"leading": true, |
|
|
|
"trailing": false |
|
|
|
"trailing": false, |
|
|
|
}); |
|
|
|
}); |
|
|
|
this._focusDebounce = BI.debounce(BI.bind(this._focus, this), BI.EVENT_RESPONSE_TIME, { |
|
|
|
this._focusDebounce = BI.debounce(BI.bind(this._focus, this), BI.EVENT_RESPONSE_TIME, { |
|
|
|
"leading": true, |
|
|
|
"leading": true, |
|
|
|
"trailing": false |
|
|
|
"trailing": false, |
|
|
|
}); |
|
|
|
}); |
|
|
|
this._blurDebounce = BI.debounce(BI.bind(this._blur, this), BI.EVENT_RESPONSE_TIME, { |
|
|
|
this._blurDebounce = BI.debounce(BI.bind(this._blur, this), BI.EVENT_RESPONSE_TIME, { |
|
|
|
"leading": true, |
|
|
|
"leading": true, |
|
|
|
"trailing": false |
|
|
|
"trailing": false, |
|
|
|
}); |
|
|
|
}); |
|
|
|
this.element |
|
|
|
this.element |
|
|
|
.keydown(function (e) { |
|
|
|
.keydown(function (e) { |
|
|
@ -86,7 +87,7 @@ BI.Input = BI.inherit(BI.Single, { |
|
|
|
this.element.addClass("bi-input-focus"); |
|
|
|
this.element.addClass("bi-input-focus"); |
|
|
|
this._checkValidationOnValueChange(); |
|
|
|
this._checkValidationOnValueChange(); |
|
|
|
this._isEditing = true; |
|
|
|
this._isEditing = true; |
|
|
|
if (this.getValue() == "") { |
|
|
|
if (this.getValue() === "") { |
|
|
|
this.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.EMPTY, this.getValue(), this); |
|
|
|
this.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.EMPTY, this.getValue(), this); |
|
|
|
this.fireEvent(BI.Input.EVENT_EMPTY); |
|
|
|
this.fireEvent(BI.Input.EVENT_EMPTY); |
|
|
|
} |
|
|
|
} |
|
|
@ -139,7 +140,7 @@ BI.Input = BI.inherit(BI.Single, { |
|
|
|
this._checkValidationOnValueChange(); |
|
|
|
this._checkValidationOnValueChange(); |
|
|
|
} |
|
|
|
} |
|
|
|
if (this.isValid() && BI.trim(this.getValue()) !== "") { |
|
|
|
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._pause === true && !/(\s|\u00A0)$/.test(this.getValue()))) { |
|
|
|
this._start = true; |
|
|
|
this._start = true; |
|
|
|
this._pause = false; |
|
|
|
this._pause = false; |
|
|
@ -147,7 +148,7 @@ BI.Input = BI.inherit(BI.Single, { |
|
|
|
this.fireEvent(BI.Input.EVENT_START); |
|
|
|
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) { |
|
|
|
if (this.isValid() || this.options.quitChecker.apply(this, [BI.trim(this.getValue())]) !== false) { |
|
|
|
this.blur(); |
|
|
|
this.blur(); |
|
|
|
this.fireEvent(BI.Input.EVENT_ENTER); |
|
|
|
this.fireEvent(BI.Input.EVENT_ENTER); |
|
|
@ -155,13 +156,13 @@ BI.Input = BI.inherit(BI.Single, { |
|
|
|
this.fireEvent(BI.Input.EVENT_RESTRICT); |
|
|
|
this.fireEvent(BI.Input.EVENT_RESTRICT); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (keyCode == BI.KeyCode.SPACE) { |
|
|
|
if (BI.isEqual(keyCode, BI.KeyCode.SPACE)) { |
|
|
|
this.fireEvent(BI.Input.EVENT_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); |
|
|
|
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_BACKSPACE); |
|
|
|
} |
|
|
|
} |
|
|
|
this.fireEvent(BI.Input.EVENT_KEY_DOWN, arguments); |
|
|
|
this.fireEvent(BI.Input.EVENT_KEY_DOWN, arguments); |
|
|
@ -185,7 +186,7 @@ BI.Input = BI.inherit(BI.Single, { |
|
|
|
|
|
|
|
|
|
|
|
// 初始状态
|
|
|
|
// 初始状态
|
|
|
|
_defaultState: function () { |
|
|
|
_defaultState: function () { |
|
|
|
if (this.getValue() == "") { |
|
|
|
if (this.getValue() === "") { |
|
|
|
this.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.EMPTY, this.getValue(), this); |
|
|
|
this.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.EMPTY, this.getValue(), this); |
|
|
|
this.fireEvent(BI.Input.EVENT_EMPTY); |
|
|
|
this.fireEvent(BI.Input.EVENT_EMPTY); |
|
|
|
} |
|
|
|
} |
|
|
@ -199,7 +200,7 @@ BI.Input = BI.inherit(BI.Single, { |
|
|
|
this.fireEvent(BI.Input.EVENT_CHANGE); |
|
|
|
this.fireEvent(BI.Input.EVENT_CHANGE); |
|
|
|
this._lastSubmitValue = BI.trim(this.getValue()); |
|
|
|
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.Controller.EVENT_CHANGE, BI.Events.EMPTY, this.getValue(), this); |
|
|
|
this.fireEvent(BI.Input.EVENT_EMPTY); |
|
|
|
this.fireEvent(BI.Input.EVENT_EMPTY); |
|
|
|
} |
|
|
|
} |
|
|
@ -209,14 +210,16 @@ BI.Input = BI.inherit(BI.Single, { |
|
|
|
_checkValidationOnValueChange: function (callback) { |
|
|
|
_checkValidationOnValueChange: function (callback) { |
|
|
|
var self = this, o = this.options; |
|
|
|
var self = this, o = this.options; |
|
|
|
var v = this.getValue(); |
|
|
|
var v = this.getValue(); |
|
|
|
if (o.allowBlank === true && BI.trim(v) == "") { |
|
|
|
if (o.allowBlank === true && BI.trim(v) === "") { |
|
|
|
this.setValid(true); |
|
|
|
this.setValid(true); |
|
|
|
callback && callback(); |
|
|
|
callback && callback(); |
|
|
|
|
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
if (BI.trim(v) == "") { |
|
|
|
if (BI.trim(v) === "") { |
|
|
|
this.setValid(false); |
|
|
|
this.setValid(false); |
|
|
|
callback && callback(); |
|
|
|
callback && callback(); |
|
|
|
|
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
var checker = o.validationChecker.apply(this, [BI.trim(v)]); |
|
|
|
var checker = o.validationChecker.apply(this, [BI.trim(v)]); |
|
|
@ -224,7 +227,7 @@ BI.Input = BI.inherit(BI.Single, { |
|
|
|
checker.then(function (validate) { |
|
|
|
checker.then(function (validate) { |
|
|
|
self.setValid(validate !== false); |
|
|
|
self.setValid(validate !== false); |
|
|
|
callback && callback(); |
|
|
|
callback && callback(); |
|
|
|
}) |
|
|
|
}); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
this.setValid(checker !== false); |
|
|
|
this.setValid(checker !== false); |
|
|
|
callback && callback(); |
|
|
|
callback && callback(); |
|
|
@ -306,7 +309,7 @@ BI.Input = BI.inherit(BI.Single, { |
|
|
|
_setEnable: function (b) { |
|
|
|
_setEnable: function (b) { |
|
|
|
BI.Input.superclass._setEnable.apply(this, [b]); |
|
|
|
BI.Input.superclass._setEnable.apply(this, [b]); |
|
|
|
this.element[0].disabled = !b; |
|
|
|
this.element[0].disabled = !b; |
|
|
|
} |
|
|
|
}, |
|
|
|
}); |
|
|
|
}); |
|
|
|
BI.Input.EVENT_CHANGE = "EVENT_CHANGE"; |
|
|
|
BI.Input.EVENT_CHANGE = "EVENT_CHANGE"; |
|
|
|
|
|
|
|
|
|
|
|