Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular show errors only when input not empty and invalid

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.

like image 312
Rob Avatar asked Dec 30 '25 12:12

Rob


1 Answers

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

like image 87
adrichman Avatar answered Jan 01 '26 02:01

adrichman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!