J
J
John2016-01-19 12:08:41
Angular
John, 2016-01-19 12:08:41

Displaying messages during Angular validation?

There is this form:

<form name="contactUsForm" class="form-horizontal" ng-submit="vm.confirmForm()">
        <div class="form-group">
            <span class="col-md-1 col-md-offset-1 text-center">
              <i class="fa fa-envelope-o bigicon"></i>
            </span>
            <div class="col-md-8">
              <input
                id="email"
                name="userEmail"
                type="email"
                ng-model="user.email"
                ng-minlength="4"
                ng-maxlength="20"
                 	placeholder="Email Address"
                class="form-control"
                required>
              <p ng-show="contactUsForm.userEmail.$error.maxlength">Your email is too long.</p>
              <p ng-show="contactUsForm.userEmail.$error.email">Your email is not valid.</p>
            </div>
        </div>
      </form>
        <div class="form-group">
          <div class="col-md-12 text-center">
            <button type="submit" class="btn btn-primary btn-lg" ng-submit="vm.confirmForm()">Submit</button>
          </div>
        </div>

Everything works here, but how to make it so that the short/long password messages are displayed only after clicking on the submit?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nicholas, 2016-01-19
Galt @Fargal_1

ng-show="contactUsForm.userEmail.$error.maxlength && contactUsForm.$submited"

Forms and fields have many interesting properties.
$submited is fine for you.
Other properties can be found here: https://docs.angularjs.org/api/ng/type/form.FormCo...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question