Using angularjs 1.3 and Bootstrap 3 here.
I am trying to validate my form for required field. I added html5 "required" attribute. I also added ng-class to highlight the error but the issue is when the form loads my input field ie texbox is already highlighted. What I am looking for is to hightlight the texbox on button click. Do I have to manually check for this and show error?
I use the below code:
<div class="m-grid-col-lg-10"
ng-class="{ 'has-error': nameForm.userName.$invalid }">
<input type="text" name="userName" required ng-model="userName"
class="form-control input-lg input-small" />
</div>
Button click:
<button class="btn btn-primary" type="button"
ng-click="done(nameForm.$valid)">
Done
</button>
JSController code:
$scope.done = function (isValid) {
if (isValid) {
$modalInstance.close();
}
else {
return false;
}
};
Here is a jsfiddle: