I have a form with select
and a button that is enabled when the form is validated. It works fine with input box. However, it the $touched does not seem to be working properly for the select. The button is enabled even when select is touched. It is supposed to turn invalid when select is touched. It only turns invalid and the button is disabled when I select an option and then select the default value. I want it to work when select is touched and user the mouse pointer away.
Here is my html:
<form role="form" name="frameVersionEditor" novalidate class="form-horizontal col-md-12">
<div class="row">
<div class="form-group col-lg-2 col-lg-push-1" ng-class="{'has-error' : frameVersionEditor.distributor.$invalid && frameVersionEditor.distributor.$touched}">
<label>Distributor</label>
<select name="distributor" data-ng-model="myDistr" data-ng-options="distributors.key as distributors.value for distributors in distributorOptions" class="form-control" required>
<option value="">Select Distributor</option>
</select>
<span ng-show="frameVersionEditor.distributor.$error.required && frameVersionEditor.distributor.$touched" class="help-block">Please select a distributor</span>
</div>
</div>
</form>
<button data-ng-click="generate()" ng-disabled="frameVersionEditor.$invalid">Generate</button>
Here is my controller:
var myApp = angular.module('myApp',[]);
myApp.controller('myController', ['$scope', function($scope) {
$scope.myDistr = [];
$scope.distributors =
[
{
'key': '0',
'value': 'A'
},
{
'key': '1',
'value': 'B'
},
{
'key': '2',
'value': 'C'
}
];
$scope.generate = function() {
//Do something
};
}]);