Click here to Skip to main content
15,895,833 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
$scope.formname.$setpristine(); resetting all the predefined validations(ex:required) but custom validation messages are not resetting to its original state

example code: The below code is working correctly means shows error messages but while resetting the form the validations not cleared

XML
<input type ="text" ng-model="studentobj.firstname" required checkexists />
<span style="color:red" ng-show="testform.$error.required && testform.$dirty && testform.$invalid">first name Required</span>
<span style="color:red" ng-show="testform.$error.checkexists ">Name Matched</span>



C#
app.directive('checkexists',function(){

    return{
        restrict:'A',
        require:'ngModel',
        link:function(scope,element,attrs,ngctrl)
        {


             ngctrl.$validators.checkexists =function(ngctrl)
             {
                 if(ngctrl=="phani")
                 {
                     return true;
                     console.log('if');

                 }
else{
    console.log('else')
    return false;
}


             }

        }

    }
Posted
Updated 15-Aug-15 7:55am
v4

1 solution

See this form on how to reset: https://docs.angularjs.org/guide/forms[^]
 
Share this answer
 
Comments
Venkata Durga Rao 15-Aug-15 13:36pm    
am asking about validation messages not values in fields
ZurdoDev 15-Aug-15 13:44pm    
What do you mean by reset the messages then? Also, that is the documentation so whatever it is you should find it there.
Venkata Durga Rao 15-Aug-15 13:58pm    
Yes,setPristine() method used for clearing the fired messages,but my custom validated messages not cleared,it should being cleared by myself like below testform.$error.checkexists =false

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900