Utilizing AngularJS and Spring MVC in my current project, I am sending JSON to a rest controller for field validation. In the event of a validation failure, an Error object is returned containing details such as:
{"validationErrors":[
{
"errorCode":"emailId",
"errorDescription":"Please enter email address."
}
]}
My concern now is how to display inline error messages on the JSP page.
Here is a snippet of my JSP code:
<label ng-model="emailLbl" for="userEmailID">Email ID</label>
<input type="email" ng-model="user.emailId" name="emailId" id="userEmailID" placeholder="Enter your email ID" />
//I need to show inline error message here
</div>
As for my JavaScript code:
//Updated angular.module('MiniApp', []);angular.module('MiniApp').controller('loginCtrl', ['$scope', '$http','$location',function($scope,$http,$location) {
$scope.loginSubmit = function(user) {
$scope.errors = [];
$scope.jsonObject = angular.copy(user);
var data1;
setTimeout(function(){
data1=document.getElementById("hiddenJson").value;
$http({
method: 'POST',
url: 'register1/login',
headers: {'Content-Type': 'application/json'},
data: data1
}).
success(function(data, status, headers, config) {
alert('Success:'+data.prospectResponseDetails.emailId+" - "+status);
$location.path('WEB-INF/pages/login-step1.jsp');
}).
error(function(data, status, headers, config) {
_showValidationErrors($scope, data.validationErrors);
$scope.errors = data.validationErrors;
});
$scope.getErrorMessage = function(errorCode) {
var error;
$scope.errors.forEach(function(error) {
if(error.errorCode === errorCode) {
error = error.errorDescription;
}
});
return error;
}
}, 200);
};
}]);