|
5 | 5 |
|
6 | 6 | define([ |
7 | 7 | "dojo/_base/declare", "mxui/widget/_WidgetBase", "dijit/_TemplatedMixin", |
8 | | - "mxui/dom", "dojo/dom", "dojo/_base/array", "dojo/_base/lang", |
| 8 | + "mxui/dom", "dojo/dom", "dojo/_base/array", "dojo/_base/lang", "dojo/dom-construct", "dojo/dom-class", |
9 | 9 | "mendix/lib/MxContext", "dijit/form/ComboBox", |
10 | 10 | "refkit/lib/XPathSource", |
11 | 11 | "refkit/lib/jquery", |
12 | 12 | "dojo/text!refkit/templates/InputReferenceSelector.html" |
13 | | -], function (declare, _WidgetBase, _TemplatedMixin, dom, dojoDom, dojoArray, dojoLang, MxContext, ComboBox, XPathSource, _jQuery, template) { |
| 13 | +], function (declare, _WidgetBase, _TemplatedMixin, dom, dojoDom, dojoArray, dojoLang, dojoConstruct, domClass, MxContext, ComboBox, XPathSource, _jQuery, template) { |
14 | 14 |
|
15 | 15 | "use strict"; |
16 | 16 |
|
@@ -177,7 +177,13 @@ define([ |
177 | 177 | callback: dojoLang.hitch(this, this.changeReceived) |
178 | 178 | }); |
179 | 179 |
|
180 | | - this._handles = [ objectHandle ]; |
| 180 | + var validationHandle = this.subscribe({ |
| 181 | + guid: obj.getGuid(), |
| 182 | + val: true, |
| 183 | + callback: dojoLang.hitch(this, this._handleValidation) |
| 184 | + }); |
| 185 | + |
| 186 | + this._handles = [ objectHandle, validationHandle ]; |
181 | 187 | this.getReferredObject(obj.get(this.objreference)); |
182 | 188 | } else { |
183 | 189 | this.comboBox.attr("disabled", true); |
@@ -220,6 +226,7 @@ define([ |
220 | 226 | setDisplayValue : function(value) { |
221 | 227 | logger.debug(this.id + ".setDisplayValue", value); |
222 | 228 | this.ignoreChange = true; |
| 229 | + this._clearValidations(); |
223 | 230 |
|
224 | 231 | if (this.comboBox) { |
225 | 232 | this.comboBox.attr("value", value); |
@@ -367,6 +374,47 @@ define([ |
367 | 374 | this.comboBox.attr("disabled", this.isInactive); |
368 | 375 | }, |
369 | 376 |
|
| 377 | + _handleValidation: function(validations) { |
| 378 | + logger.debug(this.id + "._handleValidation"); |
| 379 | + this._clearValidations(); |
| 380 | + |
| 381 | + var validation = validations[0], |
| 382 | + message = validation.getReasonByAttribute(this.objreference); |
| 383 | + |
| 384 | + if (this.readOnly) { |
| 385 | + validation.removeAttribute(this.objreference); |
| 386 | + } else if (message) { |
| 387 | + this._addValidation(message); |
| 388 | + validation.removeAttribute(this.objreference); |
| 389 | + } |
| 390 | + }, |
| 391 | + |
| 392 | + _clearValidations: function() { |
| 393 | + logger.debug(this.id + "._clearValidations"); |
| 394 | + domClass.toggle(this.domNode, "has-error", false); |
| 395 | + dojoConstruct.destroy(this._alertDiv); |
| 396 | + this._alertDiv = null; |
| 397 | + }, |
| 398 | + |
| 399 | + _showError: function(message) { |
| 400 | + logger.debug(this.id + "._showError"); |
| 401 | + if (this._alertDiv !== null) { |
| 402 | + dojoHtml.set(this._alertDiv, message); |
| 403 | + return true; |
| 404 | + } |
| 405 | + this._alertDiv = dojoConstruct.create("div", { |
| 406 | + "class": "alert alert-danger", |
| 407 | + "innerHTML": message |
| 408 | + }); |
| 409 | + dojoConstruct.place(this._alertDiv, this.domNode); |
| 410 | + domClass.toggle(this.domNode, "has-error", true); |
| 411 | + }, |
| 412 | + |
| 413 | + _addValidation: function(message) { |
| 414 | + logger.debug(this.id + "._addValidation"); |
| 415 | + this._showError(message); |
| 416 | + }, |
| 417 | + |
370 | 418 | uninitialize : function() { |
371 | 419 | logger.debug(this.id + ".uninitialize"); |
372 | 420 | this.comboBox.destroyRecursive(); |
|
0 commit comments