mercredi 25 février 2015

Angular 1.2: Is it possible to exclude an input on form dirty checking?

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="http://ift.tt/1gdxfXo"></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>



Aucun commentaire:

Enregistrer un commentaire