guy 3 years ago
parent
commit
fff0cc07df
  1. 20
      src/base/single/input/input.js

20
src/base/single/input/input.js

@ -206,24 +206,28 @@ BI.Input = BI.inherit(BI.Single, {
this._lastValue = this.getValue(); this._lastValue = this.getValue();
}, },
_checkValidationOnValueChange: function () { _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();
return; return;
} }
if (BI.trim(v) == "") { if (BI.trim(v) == "") {
this.setValid(false); this.setValid(false);
callback && callback();
return; return;
} }
var checker = o.validationChecker.apply(this, [BI.trim(v)]); var checker = o.validationChecker.apply(this, [BI.trim(v)]);
if (checker instanceof Promise) { if (checker instanceof Promise) {
checker.then(function (validate) { checker.then(function (validate) {
self.setValid(validate !== false); self.setValid(validate !== false);
callback && callback();
}) })
} else { } else {
this.setValid(checker !== false); this.setValid(checker !== false);
callback && callback();
} }
}, },
@ -256,14 +260,16 @@ BI.Input = BI.inherit(BI.Single, {
}, },
setValue: function (textValue) { setValue: function (textValue) {
var self = this;
this.element.val(textValue); this.element.val(textValue);
BI.nextTick(BI.bind(function () { BI.nextTick(function () {
this._checkValidationOnValueChange(); self._checkValidationOnValueChange(function () {
this._defaultState(); self._defaultState();
if (this.isValid()) { if (self.isValid()) {
this._lastValidValue = this._lastSubmitValue = this.getValue(); self._lastValidValue = self._lastSubmitValue = self.getValue();
} }
}, this)); });
});
}, },
getValue: function () { getValue: function () {

Loading…
Cancel
Save