I have two validations for the same field, one is touched and another is triggered on change of a drop down. Both of them get displayed at the same time, is there any possibility to hide a error message when the other error message is displayed ?
<label> First name * </label>
<input type="text" name="fname" ng-model="firstname" class="inversed" ng-minlength="2" ng-maxlength="50" ng-pattern="/^[a-zA-Z\s]*$/" maxlength="50" required />
<!-- Validation from drop down -->
<div class="hgtinpu errormessage serverside" ng-if="firstnameError">{{ firstnameError }}</div>
<!--Inline validations -->
<div ng-messages="contact.fname.$touched && contact.fname.$error">
<div class="hgtinpu errormessage clientside" ng-message="required">Please enter your first name</div>
<div class="hgtinpu errormessage" ng-message="minlength">Should contain min 2 characters</div>
<div class="hgtinpu errormessage" ng-message="maxlength">Should contain max 50 characters</div>
<div class="hgtinpu errormessage" ng-message="pattern"> Should contain alphabets and space only</div>
</div>
This is my JS code
if (!$scope.firstname)
{
$scope.firstnameError = "Please enter your first name";
// $scope.contact.fname.$touched =true;
// $scope.contact.fname.$error=true;
//return;
}
else
{
$scope.firstnameError = "";
// $scope.contact.fname.$touched =false;
// $scope.contact.fname.$error=false;
}
I tried using $touched = true but it isn't working.