adds notification msgs for failed validation. ensures that the subscriptions to the servervalidationservice are unsubscribed on $destroy = very important!
This commit is contained in:
@@ -115,6 +115,11 @@ function valPropertyMsg(serverValidationService) {
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
//when the element is disposed we need to unsubscribe!
|
||||
element.bind('$destroy', function () {
|
||||
serverValidationService.unsubscribe(currentProperty, "");
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -52,6 +52,11 @@ function valServer(serverValidationService) {
|
||||
ctrl.errorMsg = "";
|
||||
}
|
||||
});
|
||||
|
||||
//when the element is disposed we need to unsubscribe!
|
||||
element.bind('$destroy', function () {
|
||||
serverValidationService.unsubscribe(currentProperty, fieldName);
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ function valToggleMsg() {
|
||||
var showValidation = false;
|
||||
var hasError = false;
|
||||
|
||||
//add a watch to the validator for the value (i.e. $parent.myForm.value.$error.required )
|
||||
//add a watch to the validator for the value (i.e. myForm.value.$error.required )
|
||||
scope.$watch(formCtrl.$name + "." + attr.valMsgFor + ".$error." + attr.valToggleMsg, function (isInvalid, oldValue) {
|
||||
hasError = isInvalid;
|
||||
if (hasError && showValidation) {
|
||||
|
||||
@@ -37,6 +37,17 @@ function serverValidationService() {
|
||||
}
|
||||
},
|
||||
|
||||
unsubscribe: function(contentProperty, fieldName) {
|
||||
if (!contentProperty) {
|
||||
return;
|
||||
}
|
||||
callbacks = _.reject(callbacks, function (item) {
|
||||
return item.propertyAlias == contentProperty.alias &&
|
||||
(item.fieldName == fieldName ||
|
||||
((item.fieldName == undefined || item.fieldName == "") && (fieldName == undefined || fieldName == "")));
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* @ngdoc function
|
||||
* @name getCallbacks
|
||||
|
||||
@@ -17,6 +17,7 @@ function ContentEditController($scope, $routeParams, contentResource, notificati
|
||||
* @description
|
||||
* A function to handle what happens when we have validation issues from the server side
|
||||
*/
|
||||
|
||||
function handleSaveError(err) {
|
||||
//When the status is a 403 status, we have validation errors.
|
||||
//Otherwise the error is probably due to invalid data (i.e. someone mucking around with the ids or something).
|
||||
@@ -24,7 +25,7 @@ function ContentEditController($scope, $routeParams, contentResource, notificati
|
||||
if (err.status == 403) {
|
||||
//now we need to look through all the validation errors
|
||||
if (err.data && err.data.ModelState) {
|
||||
|
||||
|
||||
//get a list of properties since they are contained in tabs
|
||||
var allProps = [];
|
||||
for (var i = 0; i < $scope.content.tabs.length; i++) {
|
||||
@@ -54,6 +55,9 @@ function ContentEditController($scope, $routeParams, contentResource, notificati
|
||||
//add a generic error for the property, no reference to a specific field
|
||||
serverValidationService.addError(contentProperty, "", err.data.ModelState[e][0]);
|
||||
}
|
||||
|
||||
//add to notifications
|
||||
notificationsService.error("Validation", err.data.ModelState[e][0]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user