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

What Control Is Like ComboBox, but allows text entered to be returned?

2 Answers 51 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
pjDev
Top achievements
Rank 1
pjDev asked on 28 Nov 2011, 08:15 PM
I am writing code that needs a box like the ComboBox but with different functionality.  Can someone tell me how to accomplish this?  (either with ComboBox or some other Rad control)

Users will type text they wish to search for in a textbox/combobox type field.  I want it to give common (preset and known) choices that match what they are typing as they type (Like ComboBox Filter function).  If what they wish to type is in the list that appears, I want the user to be able to select it.  So far, this is just like the ComboBox, but here is the hitch.  If what they type is not in the list I want to return the text they type.  I do not want to require them to select form the preselected list, I just want it to help them from what others have searched for in the past.

I hope I said this clearly enough.  I appreciate your help.

P

2 Answers, 1 is accepted

Sort by
0
Accepted
Ivana
Telerik team
answered on 30 Nov 2011, 03:05 PM
Hi Paul,

The scenario described, could be achieved trough the client-side API or server-side API of the RadComboBox. In both cases you could use the TextChanged event.

Below is an example of how the described scenario could be achieved with the client-side event OnClientTextChange:
function OnClientTextChange(sender, args)
{
    var textTyped = sender.get_text();//Gets the typed text in the input field.
    if (sender.findItemByText(textTyped) == null)
    {
        //Do something with the text typed in the input field.
    } else
    {
        //The user has typed a text which corresponds to an item.
    }
}

To see how to use the server-side event OnTextChanged, you could refer to the following link: RadComboBox / OnTextChanged.

I hope this helps.

Kind regards,
Ivana
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
pjDev
Top achievements
Rank 1
answered on 30 Nov 2011, 07:14 PM
It turned out while this answer is correct and very helpful, the only thing I needed to do was set

AllowCustomText="true"

this returns a Value of ""
and Text of whatever the user typed or selected (in which case the value is the associated value).

This was all I needed.  So if anyone reading this thread wanted the user to be able to type in text and return it in the combo box even if nothing is selected, AllowCustomText="true" is your answer.  If you need to manipulate the results, use what Ivana said. 

Both are very good solutions.
Thank you,
PJ
Tags
ComboBox
Asked by
pjDev
Top achievements
Rank 1
Answers by
Ivana
Telerik team
pjDev
Top achievements
Rank 1
Share this question
or