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

5 posts, 1 answers
  1. Steve
    Steve avatar
    84 posts
    Member since:
    Aug 2013

    Posted 21 Dec 2013 Link to this post

    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>
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 23 Dec 2013 Link to this post

    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.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Steve
    Steve avatar
    84 posts
    Member since:
    Aug 2013

    Posted 23 Dec 2013 Link to this post

    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.

  5. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 25 Dec 2013 Link to this post

    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,
  6. Steve
    Steve avatar
    84 posts
    Member since:
    Aug 2013

    Posted 26 Dec 2013 Link to this post

    This works like a charm! Thanks, Princy!!!
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017