Reputation: 475
I have a multi-page (html templates) form which I am validating using Angular. Is it possible to display only certain error messages using $setValidity and ng-repeat using a string filter? If not, any suggestions?
I want to catch errors, $setValidity and then conditionally display certain error messages based on the page of the form the error was from.
Here is the Angular validation code:
///TEAM DATA
if (!$scope.formData.TeamContactFirstName) {
$scope.signupform.$setValidity('TEAM: Please provide a Team Contact First Name', false)
$scope.failedForms.team = true;
isValid = false;
}
if (!$scope.formData.TeamContactLastName) {
$scope.signupform.$setValidity('TEAM: Please provide a Team Contact Last Name', false)
$scope.failedForms.team = true;
isValid = false;
}
//PROJECT BASICS
if (!$scope.formData.Title) {
$scope.signupform.$setValidity('BASICS: Please provide a project title.', false)
$scope.failedForms.basics = true;
isValid = false;
}
if (!$scope.formData.ProjectLocation) {
$scope.signupform.$setValidity('BASICS: Please provide the location of the project', false)
$scope.failedForms.basics = true;
isValid = false;
}
Here is the repeater:
<div ng-show="signupform.$invalid" class="alert-box alert radius">
<ul>
<li ng-repeat="(key, errors) in signupform.$error">
<ul>
<li ng-repeat="e in errors"><strong>{{ key }}</strong>.</li>
</ul>
</li>
</ul>
</div>
I want to be able to only display the TEAM DATA errors with this repeater. Filter?
Upvotes: 2
Views: 245
Reputation: 5944
Quite strange use of $setValidity
, but anyways:
<div ng-show="signupform.$invalid" class="alert-box alert radius">
<ul>
<li ng-repeat="(key, errors) in signupform.$error">
<ul>
<li ng-repeat="e in errors" ng-if="key.indexOf('TEAM:') == 0"><strong>{{ key }}</strong>.</li>
</ul>
</li>
</ul>
</div>
Upvotes: 1