Dealing with this particular structure
<div ng-controller="FormController as f_ctrl">
<form ng-submit="f_ctrl.submit()" name="myForm">
<input type="text" ng-model="f_ctrl.user.username"
required
ng-minlength="4"/>
<input type="text" ng-model="f_ctrl.user.password"/>
<input type="submit" value="Submit" ng-disabled="myForm.$invalid">
</form>
</div>
With the following controller setup
.controller('FormController', [function() {
var self = this;
self.submit = function() {
console.log('User submitted form with ' + self.user.username)
}
}]);
I am encountering an issue: upon initial page load, there is already a noticeable red border around the username field, even though I have not started entering any text yet.
I would like to only highlight invalid fields after the first submission. Is there a way to achieve this using form.$invalid
?