Typeahead ngForm validation proposal #3508
Description
Hi Everyone:
I've been using some of the components in the library, and I've noticed that the typeahead validates right after the user starts typing to look up for an element. I'm unaware of the thought process of why this has been done like this.
I tried to find any issue open addressing this behavior and I couldn't find any. I would like to make a proposal or start a discussion on how the typeahead should validate or run it's validators.
Currently, when a user starts typing in the <input>
field, the directive will start looking up for any match for whatever the user is typing, also at the same time, validators are fired at that point, this validators affect, if present, the state of any ngForm reference. Assume we have this:
<form name="user">
...
<input type="text" name="name" typeahead="..." typeahead-editable="false">
...
<div ng-show="!user.name.$valid">
Invalid name for user!
</div>
</form>
As soon as the user starts typing a value the message will start showing even though that doesn't mean the user has not selected an incorrect value yet. In my opinion validation for this should happen after the user has selected a value by any means (clicking, hitting enter, etc) or if the <input>
element looses the focus, this would create a more meaningful user experience when using this component, rather than setting the value of $valid to false right away.
Right now I created a directive to detect when the blur event is fired from the typeahead element so the error message actually shows when the user has lost focus on that element, implying that either the user left the element blank because he thought it was not a required field or because he typed a valid value.
I hope we can get to improve the existing code base and usability of this element, if you have any comments please let me know.
Thanks!