Angular.js programmatically setting a form field to dirty
angularjs
Solution
Since AngularJS 1.3.4 you can use `$setDirty()` on fields (source). For example, for each field with error and marked required you can do the following:
angular.forEach($scope.form.$error.required, function(field) {
field.$setDirty();
});
Problem
I am programmatically updating some of the fields on my form with a value and I would like to set the field state to `$dirty`. Doing something like: `$scope.myForm.username.$dirty = true;` doesn't seem to work. There is a method `$setPristine` that I can use to reset the state of the field but there isn't a `$setDirty` method? So how does one go about doing this? I saw this post https://groups.google.com/forum/#!topic/angular/NQKGAFlsln4 but I can't seem to find the `$setDirty` method. I am using Angular version 1.1.5.