RadComboBox with AllowCustomText sometimes raises OnClientTextChange other time raises OnClientSelectedIndexChanged

5 posts, 1 answers
  1. Jon
    Jon avatar
    5 posts
    Member since:
    Nov 2011

    Posted 06 Nov 2012 Link to this post

    I'm using a RadComboBox.  I have AllowCustomText = "true" and Filter = "Contains" as shown below:

    <telerik:RadComboBox runat="server"
        AllowCustomText="True" Filter="Contains"
        OnClientTextChange="rcbName_ClientTextChange"
        OnClientSelectedIndexChanged="rcbName_ClientSelectedIndexChanged">
        <Items>
            <telerik:RadComboBoxItem runat="server" Text="Test"/>
            <telerik:RadComboBoxItem runat="server" Text="Tests"/>
            <telerik:RadComboBoxItem runat="server" Text="test"/>
            <telerik:RadComboBoxItem runat="server" Text="other"/>
        </Items>
    </telerik:RadComboBox>

    I'm interested in the behavior that occurs when the user does not select an item, but presses the Enter key.

    Initially, I found that when the user types text, but doesn't select an item from the matching list, then presses Enter, it raises the OnClientSelectedIndexChanged event.  That's not a problem for my situation.  However, I noticed that when the user types text that exactly matches an item from the matching list (complete word or phrase and case-sensitive), but doesn't select the matching item from the matching list, then presses Enter the OnClientSelectedIndexChanged event is not raised. This caused a problem for my situation.

    I then added the OnClientTextChange event handler.  Now if the user enters text that exactly matches an item in the list, doesn't select the item, then presses enter, the OnClientTextChange event will be raised.  But if the user enters text that doesn't exactly match, then doesn't select an item, then presses enter, the OnClientSelectedIndexChanged event is still raised.

    To test the above situation, just add the following javascript:

    function rcbName_ClientTextChange(sender, eventArgs)
    {
        alert("ClientTextChange");
    }
     
    function rcbName_ClientSelectedIndexChanged(sender, eventArgs)
    {
        alert("ClientSelectedIndexChanged");
    }

    You'll find that if you type "tes", then press Enter, the ClientSelectedIndexChanged event will be raised.  If you type "test", then press Enter, the ClientTextChange event will be raised.

    Raising the OnClientSelectedIndexChanged event when the user doesn't make a selection is an interesting occurrence itself.  The event not being raised if the text exactly matches an item is equally interesting.  Since this is all interesting, my question is, is this behavior by design?  Is it not likely to change in future releases?  I can make it work fine.  I just wanted to make sure that's the way Telerik intended and to let other users know this works this way.

    Thanks!


  2. Answer
    Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 09 Nov 2012 Link to this post

    Hello Jon,

    I have inspected the provided information and it seems there is a problem with the behavior of the control. By typing text that does not match any item in the list and then pressing Enter key OnClientSelectedIndexChanged event is not suppose to be fired. I already logged this bug for fixing in our system and updated your Telerik points as a token of gratitude for this bug report.

    By default when the Filter property is set the RadComboBox will only filter its items without making a selection when the focus is lost.

    Regards,
    Boyan Dimitrov
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jon
    Jon avatar
    5 posts
    Member since:
    Nov 2011

    Posted 09 Nov 2012 Link to this post

    OK.  I have found a work-around for my current situation.  My work-around should continue to work even after you've fixed the issue you've logged.  Thanks for taking the time to investigate the issue.
  5. wnl
    wnl avatar
    106 posts
    Member since:
    Aug 2007

    Posted 26 Feb 2013 Link to this post

    What is a work-around in this situation? I have the same problem now but I don'h have access to the newest version of Telerik's controls.
  6. Jon Shipman
    Jon Shipman avatar
    43 posts
    Member since:
    Nov 2009

    Posted 27 Feb 2013 Link to this post

    Hello wnl,

    I posted my work-around in another thread entitled: Rad Combo box enter Key press issue

    I tend to get a little wordy in my explanations so don't let that scare you off. :-)  It's a pretty simple approach.  I use the OnClientKeyPressing event to check if the user pressed enter while in the RadComboBox.  If enter is pressed, I set a global boolean flag to true.  Then if the ClientSelectedIndexChanging event is raised (and we don't always want it to be raised just because someone pressed enter), I check that flag to see if the enter key was pressed and cancel the event if I want to, then reset the global boolean flag to false.


Back to Top
UI for ASP.NET Ajax is Ready for VS 2017