3

I'm trying to toggle an error area on my form that only triggers once there is some input, it's a bit silly to have the errors all appear if the user hasn't started typing yet.

<form name="registerForm">
  <input type="email" name="email" ng-model="email" required />
</form>

<span ng-show="registerForm.email.$invalid">
  Invalid email.
</span>

This works fine once I'm typing but I want it to show no errors if the input is empty. I've tried using the model ng-hide="!email.length" but can't get it to work.

2 Answers 2

2

<span ng-show="registerForm.email.$invalid && registerForm.email.$dirty>

Sign up to request clarification or add additional context in comments.

2 Comments

The problem with this is that if the user clears the input field after having entered characters, dirty will still be false and it will show the invalid message still.
as a quick fix i used: && !registerForm.get('email').hasError('required') (using angular 6 validation), to solve the above problem. not very clean tho.
0

Try this:

<span ng-show="registerForm.email.$invalid && email>

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.