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

Pressing Enter not working for me

3 Answers 34 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Steve
Top achievements
Rank 1
Steve asked on 03 Dec 2013, 03:36 PM
I have a combobox that is filled with a datasource. It filters the dropdown as I type. When I press the enter key, it simply closes the combobox and does nothing. I tried using the onClientKeyPressing event and monitoring on the enter key, but that prevents the combobox from filtering the dropdown entries.

What I want to happen is to be able to type and the dropdown entries filter. When the I press the enter key, I want to execute some javascript code. I want to be able to execute javascript code when the user either selects an entry from the dropdown or presses the enter key.

Here is what I have that does not work.
<telerik:RadComboBox ID="CustomerSearch" runat="server" Width="180" Height="160"
     MarkFirstMatch="true" AllowCustomText="true" CssClass="CustomerSearch" AutoPostBack="false"
     OnClientKeyPressing="HandleKeyPress" EnableVirtualScrolling="true" ShowMoreResultsBox="true"
     EmptyMessage="Enter last, first to search..." BackColor="White" Skin="Forest" />
 
<asp:SqlDataSource ID="dsCustomer" runat="server"
      SelectCommand="CustomerSearchName" SelectCommandType="StoredProcedure"></asp:SqlDataSource>
 
<telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
            <script type="text/javascript">
                function searchnav(sender, args) {
                    var iframe = document.getElementById('ctl00_iMainPages');
 
                        if (sender.get_value() != null && sender.get_value() != '') {
                            iframe.src = sender.get_value() + '&T=Client';
                        }                  
                }
                function HandleKeyPress(sender, args) {
 
                    if (e.get_domEvent().keyCode == 13) {
                        searchnav(sender, args);
                    }
                }
            </script>
</telerik:RadScriptBlock>

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 04 Dec 2013, 06:17 AM
Hi Steve,

Please try the following JavaScript to achieve your scenario which works fine at my end.

JavaScript:
<script type="text/javascript">
    function HandleKeyPress(sender, args) {
        if (args.get_domEvent().keyCode == 13) {
            //if the enter key is pressed it will call the searchnav
            searchnav(sender, args);
        }
    }
    function searchnav(sender, args) {
        sender.get_text();
        }
    }
</script>

Thanks,
Shinu.
0
Steve
Top achievements
Rank 1
answered on 04 Dec 2013, 01:27 PM
The code you offered is pretty much the same as what I am currently doing. The problem is when it is checking the e.get_domEvent().keyCode == 13 in the HandleKeyPress function, the dropdown does not position itself to the first matching item being typed in the combobox. The dropdown does happen, but as I type, it is supposed to highlight the first matching item. This does not happen.

I comment out the line code inside HandleKeyPress and it does the positioning. If I execute just this:

function HandleKeyPress(sender, args) {

     if (e.get_domEvent().keyCode == 13) {
        //    searchnav(sender, args);
     }
}


It does not work. It will not highlight anything in the dropdown.
0
Steve
Top achievements
Rank 1
answered on 04 Dec 2013, 01:33 PM
I found the problem. In the HandleKeyPress function, I was checking e.get_domEvent instead of args.get_domEvent.

Thanks for your assistance.
Tags
ComboBox
Asked by
Steve
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Steve
Top achievements
Rank 1
Share this question
or