This is a migrated thread and some comments may be shown as answers.

[Solved] Catching Enter key with keydown in ComboBox

1 Answer 93 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
IT
Top achievements
Rank 1
IT asked on 19 Aug 2011, 09:35 AM
I'm trying to catch the enter key press in a ComboBox control so I can prevent the form being submitted and instead focus the next control.

I have this working fine for the standard controls, however I'm having an issue with it on a ComboBox...

$(function () {
    $("#MyCombo-input").live('keydown', function (e) {
        var keyPressed;
 
        if ((e.charCode) && (e.keyCode == 0))
            keyPressed = e.charCode
        else
            keyPressed = e.keyCode;
 
        //alert(keyPressed);
 
        if (keyPressed == 13) {
            e.preventDefault();
 
            focusNextControl();
        }
    });
});

The above code will work if the alert is in there... with the combo focused, it shows the key codes as the keys are pressed, and if enter is pressed, it will work as expected (and not submit the form).

If the alert is commented out, the form submits... it's as if some other event is firing before the e.preventDefault() is reached.

I've tried the same code on $("#MyCombo") as well as $("#MyCombo-input"), but it doesn't help.

It's worth noting that this only fails when something is selected in the combo box... if you focus the combo and hit enter without having selected anything, it works as expected.


1 Answer, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 23 Aug 2011, 02:44 PM
Hello Aleks,

 
Here is a quote of the answer in the support thread open on the same matter:

After further investigation I was able to observe the erroneous behavior. It seems that the issue is related particularly with IE8.

I am glad to inform you that we was able to address this problem and the fix will be included in the next official release of Telerik Extensions for ASP.NET MVC. For your convenience I have attached the file which includes the fix.


Best regards,
Georgi Krustev
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
ComboBox
Asked by
IT
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Share this question
or