Reputation: 1819
Is there an ng-show expression I can use to only validate this textbox only when the submit button is clicked? Currently, it's displaying the error message while the user is typing into it.
<div ng-show="!vm.validEmployerCode && !form.EmployerCode.$error.required" class="errorMessage">
You have entered an invalid code
</div>
<div class="row">
<div class="col-xs-11">
<div class="form-group">
<label class="form-label" for="Code">Code</label>
<input ng-model="vm.code" name="Code" type="text" required id="Code" />
</div>
</div>
<div class="btn-group" role="group" aria-label="...">
<button type="submit" class="btn btn-success col-md-4">
Sign Up
</button>
</div>
</div>
Upvotes: 1
Views: 64
Reputation: 136154
You could check $submitted
flag inside your form object, basically that will become a true once you submit the form. So you need to add form.$submitted
inside ng-show
directive.
Markup
<div ng-show="form.$submitted && !vm.validEmployerCode && !form.EmployerCode.$error.required"
class="errorMessage">
You have entered an invalid code
</div>
Upvotes: 2