Uh oh!
There was an error while loading. Please reload this page.
feat(material/autocomplete): add input to require selection from the panel - #27423
Conversation
a0bfd48 to
deb61a5CompareUh oh!
There was an error while loading. Please reload this page.
…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. Fixesangular#3334.
deb61a5 to
a4403f7Comparealixroyere
commented
Jul 11, 2023
Thanks for this desired feature 😸 I've got some interrogations. |
crisbeto
commented
Jul 11, 2023
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. |
alixroyere
commented
Jul 11, 2023
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. |
alixroyere
commented
Jul 11, 2023
You're right 😿 That would have been easier to use as a consumer. |
crisbeto
commented
Jul 11, 2023
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? |
alixroyere
commented
Jul 11, 2023
You mean that becomes invalid once the panel is open, and valid once closed? That could help. |
crisbeto
commented
Jul 11, 2023
Yeah basically it would be invalid only if the panel is closed and none of the option values is selected. |
alixroyere
commented
Jul 11, 2023
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 |
alixroyere
commented
Jul 11, 2023
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)? |
crisbeto
commented
Jul 12, 2023
I'm not sure I follow the last comment. The autocomplete trigger would provide itself as a validator that sets an error like |
alixroyere
commented
Jul 12, 2023
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:
|
crisbeto
commented
Jul 12, 2023
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? |
crisbeto
commented
Jul 27, 2023
Capturing what we talked about in our team meeting: we should make it so the model value is |
alixroyere
commented
Jul 27, 2023
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. Fixesangular#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.
crisbeto
commented
Aug 3, 2023
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
requireSelectioninput to the autocomplete, which when enabled will clear the input value if the user doesn't select an option from the list.Fixes#3334.