Makes the umbProperty directive check optional since these validators can exist outside of an umbProperty directive (i.e. like in a dialog for a parameter editor)

This commit is contained in:
Shannon
2015-01-06 12:03:19 +11:00
parent 69e1dd1c73
commit 97a05008b3
2 changed files with 16 additions and 8 deletions

View File

@@ -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');
@@ -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);
}
}
};

View File

@@ -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;