Reputation: 12179
Why isn't the error variable being set here? Shouldn't user.username.$error.minlength
be true when no value is in the input?
<form name="user" ng-submit="submit()">
<div class="input-wrapper">
<input placeholder="Username" ng-model="user.username" ng-minlength="2" ng-maxlength="12" />
<div ng-show="user.username.$error.minlength">Min length!</div>
</div>
<div class="input-wrapper">
<input placeholder="Password" ng-model="user.password" ng-minlength="5" ng-maxlength="15" />
<div ng-show="loginForm.password.$error.minlength">Min length!</div>
</div>
</form>
Upvotes: 0
Views: 169
Reputation: 21901
if you need to show the message when there is no value for the password you need to check the required
property.
put a name for the form
<form name="formName" ng-submit="submit()">
put a name to password
input. and the required attribute
<input name="password" placeholder="Password" ng-model="user.password" ng-minlength="5" ng-maxlength="15" required />
change the ng-show
as,
<div ng-show="formName.password.$error.required || formName.password.$error.minlength">Min length!</div>
formName.password.$error.required
will handle the status of empty input.
here is a plunker demo
Upvotes: 2