I have this very basic example. This should work in a form for multiple inputs as well.
I want a form without any required parameters. But I only want to enable the button if at least one of them is not empty.
$pristine almost works. The problem is that if I type something and delete it the button remains enabled.
Basically,
If all fields are empty -> button disabled
Else if at least one not empty -> button enabled
function ctrl($scope){
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app>
<form name="myForm" ng-controller="ctrl">
<input type="text" ng-model="name" name='myName' ng-model='myName'/>
<span>{{name}}</span>
<input type="submit" value="Submit" ng-disabled="myForm.$pristine" />
{{myForm.$pristine}}
</form>
</div>
Pristine checks whether the input field is touched or not. That's why it remains enabled after you deleted your input. Check on valid and provide some condition. Or use pattern and regex.