-
Notifications
You must be signed in to change notification settings - Fork 6.8k
feat(material/autocomplete): add input to require selection from the panel #27423
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(material/autocomplete): add input to require selection from the panel #27423
Conversation
a0bfd48
to
deb61a5
Compare
…panel Adds the `requireSelection` input to the autocomplete, which when enabled will clear the input value if the user doesn't select an option from the list. Fixes angular#3334.
deb61a5
to
a4403f7
Compare
Thanks for this desired feature 😸 I've got some interrogations. |
It'll still receive the values typed by the user, but the value will be cleared if the panel is closed without selecting an option. I was considering not pushing values to the model at all, but that would introduce issues in the case where the input value is also used for filtering the options. |
I understand but aren't these values available on the html input anyway, as with the (input) event? |
They are, but usually the expectation when using reactive forms is that you wouldn't have to interact with the DOM directly. In retrospect, we should've had two form controls: one for the input and one for the autocomplete panel, instead of combining them into one, but making the change at this point would be a massive breaking change. |
You're right 😿 That would have been easier to use as a consumer. |
There's still some time until the feature makes it into a release so we have time to iterate on it, but it's unclear to me what the alternative would be. We could add a custom validator in the autocomplete that only becomes invalid once the panel is closed? |
You mean that becomes invalid once the panel is open, and valid once closed? That could help. |
Yeah basically it would be invalid only if the panel is closed and none of the option values is selected. |
Or add a new input that would set what to put in the control (the user typing + the selected/empty values = default) or (only the selected/empty values). Is it still a massive breaking change? |
Well in fact this is more an "AND" than an "OR". Because the validity issue would still be here for the combination of "requiredSelection=true" + default value for the other new parameter |
Are you're talking about the validity calculated by the validator (if control is valid for this validator), or about the validity of the validator (if validator is removed or something)? |
I'm not sure I follow the last comment. The autocomplete trigger would provide itself as a validator that sets an error like |
Then, would this error be there only when selection panel is open or after panel close too? If this is also applied when panel is closed:
|
The error would be there if the panel is closed and the value is null. Since it's cleared when the user closes without selecting anything, that should guarantee that it's among the options. That won't catch invalid values set through |
I was more thinking about setting a static invalid state as long as panel is open, and remove it once panel is closed. That would lead to more consistent behaviours, with requireSelection auto cleanings |
Well in fact what you propose may be better to match the input name "requireSelection". But some real life usages need to only "forceSelection" on existing values, not to require one to be set. Could there be something to cover this case? |
Capturing what we talked about in our team meeting: we should make it so the model value is |
nice ! |
…panel (angular#27423) Adds the `requireSelection` input to the autocomplete, which when enabled will clear the input value if the user doesn't select an option from the list. Fixes angular#3334.
…when requireSelection is enabled Follow-up to angular#27423 based on the feedback. Usually `mat-autocomplete` assigns to the model as the user is typing which may not be desired when `requireSelection` is enabled, because at the end of the selection either an option value will set or it'll be reset. These changes add a condition so that the value isn't assigned while typing and `requireSelection` is enabled.
I've sent out #27572 based on the discussion here. It's worth noting that I decided to keep the model value while the user is typing, instead of resetting it to |
…when requireSelection is enabled Follow-up to angular#27423 based on the feedback. Usually `mat-autocomplete` assigns to the model as the user is typing which may not be desired when `requireSelection` is enabled, because at the end of the selection either an option value will set or it'll be reset. These changes add a condition so that the value isn't assigned while typing and `requireSelection` is enabled.
…when requireSelection is enabled (#27572) Follow-up to #27423 based on the feedback. Usually `mat-autocomplete` assigns to the model as the user is typing which may not be desired when `requireSelection` is enabled, because at the end of the selection either an option value will set or it'll be reset. These changes add a condition so that the value isn't assigned while typing and `requireSelection` is enabled. (cherry picked from commit 77ffdf9)
…when requireSelection is enabled (#27572) Follow-up to #27423 based on the feedback. Usually `mat-autocomplete` assigns to the model as the user is typing which may not be desired when `requireSelection` is enabled, because at the end of the selection either an option value will set or it'll be reset. These changes add a condition so that the value isn't assigned while typing and `requireSelection` is enabled.
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Adds the
requireSelection
input to the autocomplete, which when enabled will clear the input value if the user doesn't select an option from the list.Fixes #3334.