1

I have a form with some angular validation, which I don't want to run at page load. Here is a stripped down example of my form:

<form ng-submit="vm.submit()" name="form" novalidate>
    <input class="form-control" ng-model="vm.userName" required />
    <button ng-disabled="form.$invalid && !form.vm.userName.$pristine" type="submit">Log In</button>
</form>

I'm attempting to turn off initial validation with !form.vm.userName.$pristine, as the user won't have touched the username text box yet. However, this isn't working and the form validates as usual on page load. Am I missing something?

1
  • 1
    You can also use form.$pristine which is more general, in case you have more than one input field Commented Oct 5, 2015 at 20:44

1 Answer 1

2

You need to give input a name, so that ngFormController can register this element under and its validation rules. Then you would be able to check form.userName.$pristine:

<form ng-submit="vm.submit()" name="form" novalidate>
    <input class="form-control" name="userName" ng-model="vm.userName" required />
    <button ng-disabled="form.$invalid && !form.userName.$pristine" type="submit">Log In</button>
</form>
Sign up to request clarification or add additional context in comments.

Comments

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.