Skip to content

Commit 4f59421

Browse files
author
Jelte Lagendijk
committed
Fix #2: Validation feedback & executeMF
1 parent 9e210e3 commit 4f59421

5 files changed

Lines changed: 57 additions & 8 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ test/.project
1212
*.lock
1313
.idea/
1414

15+
dist/
16+
1517
node_modules/
1618
.editorconfig
1719
*DS_Store*

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
{
22
"name": "refkit",
3-
"version": "2.0.1",
3+
"version": "2.1.0",
44
"description": "",
55
"license": "",
66
"author": "",
77
"private": true,
8-
"dependencies": {
9-
},
8+
"dependencies": {},
109
"devDependencies": {
1110
"grunt": "0.4.5",
1211
"grunt-contrib-clean": "^0.6.0",
@@ -31,4 +30,4 @@
3130
"scripts": {
3231
"test": "grunt test"
3332
}
34-
}
33+
}

src/package.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<package xmlns="http://www.mendix.com/package/1.0/">
3-
<clientModule name="refkit" version="2.0.1" xmlns="http://www.mendix.com/clientModule/1.0/">
3+
<clientModule name="refkit" version="2.1.0" xmlns="http://www.mendix.com/clientModule/1.0/">
44
<widgetFiles>
55
<widgetFile path="refkit/InputRefSelector.xml"/>
66
</widgetFiles>

src/refkit/widget/InputRefSelector.js

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
define([
77
"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",
99
"mendix/lib/MxContext", "dijit/form/ComboBox",
1010
"refkit/lib/XPathSource",
1111
"refkit/lib/jquery",
1212
"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) {
1414

1515
"use strict";
1616

@@ -177,7 +177,13 @@ define([
177177
callback: dojoLang.hitch(this, this.changeReceived)
178178
});
179179

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 ];
181187
this.getReferredObject(obj.get(this.objreference));
182188
} else {
183189
this.comboBox.attr("disabled", true);
@@ -220,6 +226,7 @@ define([
220226
setDisplayValue : function(value) {
221227
logger.debug(this.id + ".setDisplayValue", value);
222228
this.ignoreChange = true;
229+
this._clearValidations();
223230

224231
if (this.comboBox) {
225232
this.comboBox.attr("value", value);
@@ -367,6 +374,47 @@ define([
367374
this.comboBox.attr("disabled", this.isInactive);
368375
},
369376

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+
370418
uninitialize : function() {
371419
logger.debug(this.id + ".uninitialize");
372420
this.comboBox.destroyRecursive();

test/widgets/refkit.mpk

448 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)