1

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>

1 Answer 1

2

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>
Sign up to request clarification or add additional context in comments.

1 Comment

Is there any way to supress the error message after the user attempts to submit, gets the error and then enters new input? I would like the message to be hidden while they're typing and fixing the data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.