Unplanned
Last Updated: 30 Mar 2021 13:47 by ADMIN
Simon
Created on: 17 Mar 2021 06:44
Category: AutoCompleteBox
Type: Feature Request
2
AutoCompleteBox: Suggestion should only be displayed while focused

Hi,

under certain circumstances, RadAutoCompleteBoxes (at least in the "SuggestAppend" mode)  have a discrepancy between what is displayed and what is actually selected/in their SearchText property.

Steps to reproduce:

- Execute the attached project

- Focus the AutoCompleteBox on the top left.

- type the number zero (0) (for demo purposes, all items have names that look like 00001, 00002, 00004, ...)

- You should now see the Dropdown opening and the suggestion mechanism beginning to suggest the first item in the list. You should also see that the SearchText property that is bound to ViewModel contains the single zero you just typed. The selected item is still NULL as expected.

- Now, instead of typing anything else, click out of the AutoCompleteBox and focus another control (I added the WatermarkBox on the right side to allow for that)

- This is the point where the discrepancy occurs: The viewmodel still only sees the zero you typed and no item is selected. BUT: the AutoCompleteBox now shows the full item name as if it was selected correctly, see the attached screenshot.

As a user who does not have the controls on the right side to show me what is actually happening under the hood, I have no chance of knowing what is actually selected (and if anything is selected at all). To me it looks like the AutoCompleteBox just selected the first item for me. If this is what I wanted, I would have no reason to think that nothing is actually selected.

Since the ViewModel does not know anything about the additional text that is displayed, I (now as the programmer) have afaik no chance to add a workaround that selects the corresponding item when the control loses focus.

 

What I think it should look like:

There are two possibilities:

1. As soon as the control loses focus, the suggestion should disappear, leaving me with a single zero in the text box and nothing selected.

2. There could be a second property where I can bind to the full text in the textbox (including the suggestion) so I as the programmer can decide what to do with the suggestion once the control loses focus.

 

Best regards

Simon Müller

Hofmann Fördertechnik GmbH

 

PS.: If you click back into the AutoCompleteBox after defocusing it, you can then actually edit the suggestion as if it was text you inserted in the first place. But only after your first key press, the ViewModel is updated to the full string that is displayed in the textbox.

6 comments
ADMIN
Vladimir Stoyanov
Posted on: 30 Mar 2021 13:47

Hello Simon,

Thank you for the confirmation. 

I have gone ahead and approved this feature request by moving its status to "Unplanned". I also logged an internal item for it. Аs a small gesture of gratitude for bringing this to our attention, I have also added some telerik points to your account. 

Should you manage to replicate the behavior observed on your end in the shared project, please send it over and I will investigate the scenario further. Note, that you can also open a new ticket and send us the updated project.

Regards,
Vladimir Stoyanov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Simon
Posted on: 24 Mar 2021 15:27

Hello Vladimir,

yes your understanding of our requirement is correct.

With the new option activated, whenever the AutoCompleteBox loses focus (through actions other than pressing tab, enter, or escape), it should only display the text that was actually typed by the user.

As for the problem with the workaround: Unfortunately, the lower dispatcher priority does not seem to help and I was not yet able to provoke the same behavior in the sample project. The problem seems to be some kind of race condition since it seems to work sometimes but then it suddenly stops working again (in those cases, the setter for the SelectedItem is never called). I will continue debugging and report back if I manage to reproduce the behavior. Thank you for your help so far!

 

Regards

Simon Müller

ADMIN
Vladimir Stoyanov
Posted on: 24 Mar 2021 12:29

Hello Simon,

Thank you for the updates. 

With regards to introducing the functionality as a new property, I want to make sure that I have understood your requirement well. My understanding is that you want to have the option of the appended text being cleared when the RadAutoCompleteBox loses focus. Can you confirm that my understanding is correct? This will help our developers when they start implementing the feature. 

As for the scenario of clicking the items in the dropdown, can you try reducing the DispatcherPriority in the LostFocus event? Here is what I have in mind:

private void CustomAutoCompleteBox_LostFocus(object sender, RoutedEventArgs e)
        {
            this.Dispatcher.BeginInvoke(new Action(() =>
            {
                // to change the selection
                this.HandleKeyDown(Key.Tab);

                // to avoid changing the selection

                //this.HandleKeyDown(Key.Escape);
            }), DispatcherPriority.ContextIdle);
        }

If the above suggestion does not help, may I ask you to modify the sample project in order to better represent your setup and send it back? This will hopefully allow me to investigate further and better assist you.

I am looking forward to your reply.

Regards,
Vladimir Stoyanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Simon
Posted on: 23 Mar 2021 15:19

Addition to my last reply: While the CustomAutoCompleteBox control works flawlessly in the demo application, it somehow does not seem to work in our project: Whenever I click one of the suggestions from the dropdown, the text is reset and the SelectedItem is still null.

I set some breakpoints in both projects and it looks like the CustomAutoCompleteBox in the demo project already has the SelectedItem set before the control loses focus, while in our project, the SelectedItem is still null at that point (thus, causing the box to be reset by the simulated escape key stroke).

 

Simon
Posted on: 23 Mar 2021 14:42

Hello Vladimir,

thank you for the provided workaround. Indeed, the CustomAutoCompleteBox in your updated sample project now behaves the way I would expect it to (with Key.Escape).

For now, I will update our projects to use the CustomAutoCompleteBox where the default behavior of RadAutoCompleteBox might be irritating. However, simulating key presses to get the desired behavior feels a bit hacky... an out-of-the-box solution (as an additional property) would be much appreciated.

 

Regards

Simon Müller

ADMIN
Vladimir Stoyanov
Posted on: 23 Mar 2021 13:50

Hello Simon,

Thank you for the shared picture and sample project. 

I checked it out and I can agree that the described behavior can be confusing to the end user. That said, you can control whether the suggestion is selected or not by handling the LostFocus event of the control. Inside the event, you can use the protected HandleKeyDown method by passing Key.Enter or Key.Escape as a parameter to either select or clear the highlighted item.

I am attaching the sample project updated to demonstrate the above mentioned approach for your reference. Do check it out and let me know, if it helps.

Regards,
Vladimir Stoyanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Attached Files: