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

[Solved] RadComboBox with AllowCustomText sometimes raises OnClientTextChange other time raises OnClientSelectedIndexChanged

4 Answers 259 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Jon
Top achievements
Rank 1
Jon asked on 06 Nov 2012, 06:37 PM
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!


4 Answers, 1 is accepted

Sort by
0
Accepted
Boyan Dimitrov
Telerik team
answered on 09 Nov 2012, 05:01 PM
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.
0
Jon
Top achievements
Rank 1
answered on 09 Nov 2012, 09:04 PM
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.
0
wnl
Top achievements
Rank 1
answered on 26 Feb 2013, 02:00 PM
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.
0
Jon Shipman
Top achievements
Rank 1
answered on 27 Feb 2013, 05:35 PM
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.


Tags
ComboBox
Asked by
Jon
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
Jon
Top achievements
Rank 1
wnl
Top achievements
Rank 1
Jon Shipman
Top achievements
Rank 1
Share this question
or