Skip to content

Commit

Permalink
Makes the umbProperty directive check optional since these validators…
Browse files Browse the repository at this point in the history
… can exist outside of an umbProperty directive (i.e. like in a dialog for a parameter editor)
  • Loading branch information
Shazwazza committed Jan 6, 2015
1 parent 69e1dd1 commit 97a0500
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
Expand Up @@ -20,15 +20,15 @@ function valPropertyValidator(serverValidationManager) {
},

// The element must have ng-model attribute and be inside an umbProperty directive
require: ['ngModel', '^umbProperty'],
require: ['ngModel', '?^umbProperty'],

restrict: "A",

link: function (scope, element, attrs, ctrls) {

var modelCtrl = ctrls[0];
var propCtrl = ctrls[1];

var propCtrl = ctrls.length > 1 ? ctrls[1] : null;
// Check whether the scope has a valPropertyValidator method
if (!scope.valPropertyValidator || !angular.isFunction(scope.valPropertyValidator)) {
throw new Error('val-property-validator directive must specify a function to call');
Expand All @@ -46,12 +46,16 @@ function valPropertyValidator(serverValidationManager) {
if (result.isValid === true) {
// Tell the controller that the value is valid
modelCtrl.$setValidity(result.errorKey, true);
propCtrl.setPropertyError(null);
if (propCtrl) {
propCtrl.setPropertyError(null);
}
}
else {
// Tell the controller that the value is invalid
modelCtrl.$setValidity(result.errorKey, false);
propCtrl.setPropertyError(result.errorMsg);
modelCtrl.$setValidity(result.errorKey, false);
if (propCtrl) {
propCtrl.setPropertyError(result.errorMsg);
}
}
};

Expand Down
Expand Up @@ -7,12 +7,16 @@
**/
function valServer(serverValidationManager) {
return {
require: ['ngModel', '^umbProperty'],
require: ['ngModel', '?^umbProperty'],
restrict: "A",
link: function (scope, element, attr, ctrls) {

var modelCtrl = ctrls[0];
var umbPropCtrl = ctrls[1];
var umbPropCtrl = ctrls.length > 1 ? ctrls[1] : null;
if (!umbPropCtrl) {
//we cannot proceed, this validator will be disabled
return;
}

var watcher = null;

Expand Down

0 comments on commit 97a0500

Please sign in to comment.