In the example beneath, is it possible to ignore the dirty state of the dropdown list? Now it get's dirty if the user changes the selected person. But I don't care if this field is dirty in my form validation.
function TestingCtrl($scope) {
$scope.company = '';
$scope.persons = [{
name: 'Alice'
}, {
name: 'Bob'
}];
$scope.selectedPerson = $scope.persons[0];
$scope.checkForm = function() {
if ($scope.personForm.$dirty) {
alert('Form is dirty');
} else {
alert('Form is clean');
}
}
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular.min.js"></script>
<div ng-app>
<div ng-controller="TestingCtrl">
<form name="personForm" novalidate>
Company:
<input type="text" ng-model="company" required>
<br>Persons:
<select ng-options="p.name for p in persons" ng-model="selectedPerson"></select>
</form>
<br>
<button ng-click="checkForm()">Check if dirty</button>
</div>
</div>