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

Autocomplete hightlights item in dropdown but doesn't actually select it

4 Answers 70 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Steve
Top achievements
Rank 1
Steve asked on 21 Dec 2013, 03:25 PM
I have a combobox on a form that is loaded server side. When I type the name of a person in the combobox, it highlights the name in the dropdown and also completes the name in the text area. But, when I hit the enter key it isn't selecting the item. I have an OnClientKeyPressing event set to handle the keystrokes and check for the enter key. But, the get_value() is blank. But, If I actually click on the item in the dropdown, then the get_value() returns a value.

If the items is found in the dropdown, and is highlighted in the dropdown list and autocompletes the text field, why isn't it selecting that item and allowing me to get the value for it with the get_value() method?

<telerik:RadComboBox ID="CustomerSearch" runat="server" Width="180" Height="160"
        MarkFirstMatch="true" AllowCustomText="true" CssClass="CustomerSearch" AutoPostBack="true"
       
EnableVirtualScrolling="true" ShowMoreResultsBox="true" OnTextChanged="CustomerSearch_TextChanged"
        OnSelectedIndexChanged="CustomerSearch_SelectedIndexChanged" OnClientKeyPressing="HandleKeyPress"
        EmptyMessage="Enter last, first to search..." BackColor="White" Skin="Forest" />
 
 
<script type="text/javascript">
      function HandleKeyPress(sender, args) {
              if (args.get_domEvent().keyCode == 13) {
                        //this alert message is not null. it is an empty string.
                        alert(sender.get_value());
              }
      }
</script>

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 23 Dec 2013, 06:15 AM
Hi Steve,

Please try the following code snippet to get the highlighted item on OnClientKeyPressing event of RadComboBox.

JavaScript:
<script type="text/javascript">
    function HandleKeyPress(sender, args) {
        if (args.get_domEvent().keyCode == 13) {
            alert(args._domEvent.target.value);
 
        }
    }
</script>

Thanks,
Princy.

0
Steve
Top achievements
Rank 1
answered on 24 Dec 2013, 12:21 AM
Thanks Princy, but that isn't returning what I need.

Assume the data in the combobox is as follows:

Text                   Value
Doe, John           692
Doe, Jane           691
Smith, Bob          302

When I type, the text value will display in the dropdown, will be highlighted and also autocomplete the textbox.
So If I start typing "Smi" in the combobox, "Smith, Bob" will be the first item in the dropdown and will be highlighted.
It will also autocomplete the combobox. So, If I simply press the enter key, your code is giving me "Smith, Bob".
I need to get the value, 302.

0
Accepted
Princy
Top achievements
Rank 2
answered on 26 Dec 2013, 02:51 AM
Hi Steve,

Please try the following JavaScript which works fine at my end.

JavaScript:
<script type="text/javascript">
    function HandleKeyPress(sender, args) {
        if (args.get_domEvent().keyCode == 13) {
            alert("Text :"+ args._domEvent.target.value);
            var text = args._domEvent.target.value;
            alert("Value :"+sender.findItemByText(text).get_value());
 
        }
    }
</script>

Thanks,
Princy,
0
Steve
Top achievements
Rank 1
answered on 26 Dec 2013, 11:54 PM
This works like a charm! Thanks, Princy!!!
Tags
ComboBox
Asked by
Steve
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Steve
Top achievements
Rank 1
Share this question
or