From 5e661be6747a3385d9fec890702d4953f64d7266 Mon Sep 17 00:00:00 2001 From: windy <1374721899@qq.com> Date: Mon, 9 Nov 2020 16:44:31 +0800 Subject: [PATCH] =?UTF-8?q?KERNEL-6054=20feat:=20textarea=E6=94=AF?= =?UTF-8?q?=E6=8C=81validationChecker=E4=BB=A5=E5=BC=B9=E5=87=BA=E6=B0=94?= =?UTF-8?q?=E6=B3=A1=E5=BC=B9=E7=AA=97=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- changelog.md | 3 ++ demo/js/base/editor/demo.textarea_editor.js | 6 +++- src/base/single/editor/editor.textarea.js | 40 ++++++++++++++++----- 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/changelog.md b/changelog.md index 8a3c05143..da80aa200 100644 --- a/changelog.md +++ b/changelog.md @@ -1,4 +1,7 @@ # 更新日志 +2.0(2020-11) +- bi.textarea_editor支持气泡提示报错 + 2.0(2020-10) - 支持Composition API - pane和loadingPane支持加载时自定义提示文本 diff --git a/demo/js/base/editor/demo.textarea_editor.js b/demo/js/base/editor/demo.textarea_editor.js index 11a9ace06..4eb6356dc 100644 --- a/demo/js/base/editor/demo.textarea_editor.js +++ b/demo/js/base/editor/demo.textarea_editor.js @@ -8,7 +8,11 @@ Demo.CodeEditor = BI.inherit(BI.Widget, { cls: "bi-border", width: 600, height: 400, - watermark: "请输入内容" + watermark: "请输入内容", + errorText: "检测内容有误", + validationChecker: function (v) { + return BI.isNotEmptyString(v); + }, }); editor.on(BI.TextAreaEditor.EVENT_FOCUS, function () { BI.Msg.toast("Focus"); diff --git a/src/base/single/editor/editor.textarea.js b/src/base/single/editor/editor.textarea.js index 9b50d8556..37be81a9f 100644 --- a/src/base/single/editor/editor.textarea.js +++ b/src/base/single/editor/editor.textarea.js @@ -8,7 +8,11 @@ BI.TextAreaEditor = BI.inherit(BI.Single, { _defaultConfig: function () { return BI.extend(BI.TextAreaEditor.superclass._defaultConfig.apply(), { baseCls: "bi-textarea-editor", - value: "" + value: "", + errorText: "", + validationChecker: function () { + return true; + }, }); }, @@ -38,15 +42,15 @@ BI.TextAreaEditor = BI.inherit(BI.Single, { }); this.content.element.on("input propertychange", function (e) { + self._checkError(); self._checkWaterMark(); self.fireEvent(BI.TextAreaEditor.EVENT_CHANGE); }); this.content.element.focus(function () { - if (self.isValid()) { - self._focus(); - self.fireEvent(BI.TextAreaEditor.EVENT_FOCUS); - } + self._checkError(); + self._focus(); + self.fireEvent(BI.TextAreaEditor.EVENT_FOCUS); BI.Widget._renderEngine.createElement(document).bind("mousedown." + self.getName(), function (e) { if (BI.DOM.isExist(self) && !self.element.__isMouseInBounds__(e)) { BI.Widget._renderEngine.createElement(document).unbind("mousedown." + self.getName()); @@ -55,10 +59,9 @@ BI.TextAreaEditor = BI.inherit(BI.Single, { }); }); this.content.element.blur(function () { - if (self.isValid()) { - self._blur(); - self.fireEvent(BI.TextAreaEditor.EVENT_BLUR); - } + self._setErrorVisible(false); + self._blur(); + self.fireEvent(BI.TextAreaEditor.EVENT_BLUR); BI.Widget._renderEngine.createElement(document).unbind("mousedown." + self.getName()); }); if (BI.isKey(o.value)) { @@ -112,6 +115,10 @@ BI.TextAreaEditor = BI.inherit(BI.Single, { } }, + _checkError: function () { + this._setErrorVisible(this.isEnabled() && !this.options.validationChecker(this.getValue())); + }, + _focus: function () { this.content.element.addClass("textarea-editor-focus"); this._checkWaterMark(); @@ -122,6 +129,20 @@ BI.TextAreaEditor = BI.inherit(BI.Single, { this._checkWaterMark(); }, + _setErrorVisible: function (b) { + var o = this.options; + var errorText = o.errorText; + if (BI.isFunction(errorText)) { + errorText = errorText(BI.trim(this.getValue())); + } + if (!this.disabledError && BI.isKey(errorText)) { + BI.Bubbles[b ? "show" : "hide"](this.getName(), errorText, this, { + adjustYOffset: 2 + }); + return BI.Bubbles.get(this.getName()); + } + }, + focus: function () { this._focus(); this.content.element.focus(); @@ -138,6 +159,7 @@ BI.TextAreaEditor = BI.inherit(BI.Single, { setValue: function (value) { this.content.element.val(value); + this._checkError(); this._checkWaterMark(); },