Reputation: 393
My application so far is working great. It is not a form (no form tagged used) but it is a series of input boxes that a user must enter. Each input box that a user fills, I am adding an orange border on that input field. I am doing that through:
app.css:
#modifyTop .ng-dirty{
border: 2px orange;
}
index.html: ...
<body id="modifyTop" name="modifyTop" ng-controller="ModifyPageCtrl">
<button ng-click=save()>Save</button>
....
Inside this index.html is a save button. Once I hit the save button, the border field goes away. I am doing this through (I used jQuery inside an Angular controller, not sure if thats acceptable):
ModifyPageCtrl.js: ....
function save(){
....
$('#modifyTop .ng-dirty').removeClass('ng-dirty')
...
}
So the problem is the following. After hitting save, if say the user wants to change again a particular input field, then it does not make that orange border show up. Only the fields that were previously untouched/not modified have the border appear. I have to reload the page, to make the border appear again in those particular input fields. Can someone please provide examples on how I can make this work? I understand I have given very small snippets of my code thats because my work doesn't allow me to paste company code but I will try to provide more details if people are unable to help with the provided information. Also, would like to mention that my app has no errors- this is a enhancement fix that i am working on. Thank you
Upvotes: 1
Views: 381
Reputation: 31950
You need to use $setPristine():
http://docs.angularjs.org/api/ng/type/form.FormController
From the docs:
Sets the form to its pristine state.
This method sets the form's $pristine state to true, the $dirty state to false, removes the ng-dirty class and adds the ng-pristine class. Additionally, it sets the $submitted state to false.
This method will also propagate to all the controls contained in this form.
Upvotes: 1