From 307bc13b00ed15e0d0178aa3ebf91285ab297d89 Mon Sep 17 00:00:00 2001 From: guy Date: Mon, 9 May 2022 22:25:57 +0800 Subject: [PATCH] feature: checker --- src/base/single/input/input.js | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/base/single/input/input.js b/src/base/single/input/input.js index 41e1ca0de..145129dc2 100644 --- a/src/base/single/input/input.js +++ b/src/base/single/input/input.js @@ -207,13 +207,24 @@ BI.Input = BI.inherit(BI.Single, { }, _checkValidationOnValueChange: function () { - var o = this.options; + var self = this, o = this.options; var v = this.getValue(); - this.setValid( - (o.allowBlank === true && BI.trim(v) == "") || ( - BI.isNotEmptyString(BI.trim(v)) && o.validationChecker.apply(this, [BI.trim(v)]) !== false - ) - ); + if (o.allowBlank === true && BI.trim(v) == "") { + this.setValid(true); + return; + } + if (BI.trim(v) == "") { + this.setValid(false); + return; + } + var checker = o.validationChecker.apply(this, [BI.trim(v)]); + if (checker instanceof Promise) { + checker.then(function (validate) { + self.setValid(validate !== false); + }) + } else { + this.setValid(checker !== false); + } }, focus: function () {