Select an item with Enter key for RadTextBox with Autocompletion without closing a form that implements "AcceptButton"

1 Answer 69 Views
TextBox
Carlos
Top achievements
Rank 1
Carlos asked on 14 Jun 2023, 10:30 AM

Hi,

we have a problem when using the Enter key to select an item in a RadTextBox with Autocompletion because it's triggering the closing of the form, instead of just selected the item.

We have a simple form with a RadTextBox with Autocompletion enabled. In this form, we also have a Button that is used to close the window. This form has the "AcceptButton" property set to this Button. Once we select the RadTextBox and start typing, the autocompletion "dropdown" is shown with the multiple options. We scroll the options with the Arrow keys, and we want to select one element by pressing the Enter key. But, once the Enter key is pressed, the "AcceptButton" is triggered in the form, and the form closes. We only want to select the item with the Enter key without closing the window. Is this possible?

Note: We can't get rid of the "AcceptButton" functionality for the form, since it's a must for all forms in our application.

We attached a sample project with the reproduceable issue.

Please let us know how to achieve this functionality.

Thank you.

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 19 Jun 2023, 05:47 AM

Hi, Carlos,

Thank you for the provided sample project. I was able to reproduce the observed behavior. The autocomplete popup for RadTextBox is expected to be closed when pressing Enter. 

The possible solution that I can suggest is to leave the property setting of the Button.DialogResult to OK and comment the line of code with setting the form's AcceptButton. As a result, the autocomplete item will be selected after pressing Enter, the form wouldn't be closed in this case. Once the button is focused and you hit Enter, the form will be closed. Please give this approach a try and see how it works on your end.

Is this behavior applicable for your scenario?

Regards,
Dess | Tech Support Engineer, Principal
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.

Carlos
Top achievements
Rank 1
commented on 19 Jun 2023, 09:19 AM

Hi Dess,

thank you for the suggestion. This scenario works for a small case like the example I uploaded, but the main issue we have is that we have hundreds of dialogs, and some of them might contain these dropdown controls. If we follow your suggestion we would have to change all windows, and we would also have to rely on the button to be focused, which is not acceptable for us since the user should be able to close any window that has an accept button by just pressing the enter key. This functionality is achieved by using the form's "AcceptButton" and it's already implemented in our application.

Is there an alternative approach? for example to override an event of this dropdown to know if the autocomplete is opened? or something else that we can try in code?

Please let me know,

thank you

Dess | Tech Support Engineer, Principal
Telerik team
commented on 21 Jun 2023, 02:30 PM

Hi, Carlos,

Indeed, I understand that it requires development efforts and it may depend on the number of places that should be fine-tuned. However,  it is important to decide what action to be executed when pressing the Enter key - should we close the opened autocomplete popup for the RadTextBox or close the entire dialog? Once we know which has higher priority as an action, we can think about an appropriate solution and provide further assistance.

I am looking forward to your reply.

Carlos
Top achievements
Rank 1
commented on 21 Jun 2023, 03:00 PM

Hi Dess,

the expected behaviour in this case is to be able to select an item using the enter key in the "autocompletion dropdown", without closing the window. Once you are out of the "autocomplete dropdown selection" and an item has been selected, the window should close when pressing the enter key (defined by the AcceptButton property).

Please note that this only happens with this control, and for example the RadDropDownList has the correct expected behaviour (selecting with Enter and closing the "dropdown").

I've attached another example including the RadDropDownList where this scenario can be replicated (RadDropDownList working but RadTextBox not working).

If you require more information, please let me know.

Dess | Tech Support Engineer, Principal
Telerik team
commented on 26 Jun 2023, 09:41 AM

Hi, Carlos,

Thank you for the additional information. Indeed, RadDropDownList works correctly as it uses its own popup which handles the Enter key. The autocomplete functionality in RadTextBox is set via the AutoCompleteCustomSource property. Since the RadTextBox control internally hosts the standard TextBox, its autocomplete functionality comes from it as well. Hence, the popup that shows the autocomplete suggestions is the standard popup, not the one used in RadDropDownList:

RadTextBox with the autocomplete popup:

 

RadDropDownList: Clicking the arrow button shows the drop down:

If the RadDropDownList.AutoCompleteMode property is set to Suggest, pressing "L" will show the autocomplete popup which is different than the one used in RadTextBox:

The standard MS TextBox behaves in exactly the same way like RadTextBox does and also closes the form after pressing Enter. I have extended the project to test the precise case:

As a conclusion, I can say that this behavior is specific for the MS TextBox and it is not coming from any internal logic of RadTextBox.

I have invested some time to implement two possible approaches in the attached project. The first one (recommended) is to use a RadDropDownList with collapsed button and benefit its autocomplete behavior with its own popup. The second option is to cancel the FormClosing event when the RadTextBox control is focused. Please give the sample project a try and see how these approaches will for you.

 

Tags
TextBox
Asked by
Carlos
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or