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

combobox text client side

1 Answer 59 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Harika
Top achievements
Rank 1
Harika asked on 17 Apr 2012, 10:49 PM
Hi Team,

I have a rad combobox for which i am checking the check boxes on client side based on the text entered using the below code.

combo.get_items().getItem(i).set_checked(

 

true);

 but it did not show the text of all the items checked which matches the typed criteria, instead shows the text of only the first matching item. and after any event on the page the text chnages (to the correct text).

for example if i type a in the combo box, it cheks the items 'apple' and 'ant' but shows the text of the combox only as 'apple' instead of 'apple, ant' and once i click on any button it changes to 'apple, ant'

Tried to use combo.set_text("mytext"), but did not work

Thanks for any suggestions

1 Answer, 1 is accepted

Sort by
0
Ivana
Telerik team
answered on 20 Apr 2012, 11:16 AM
Hi,

Try the following workaround:
<script type="text/javascript" language="javascript">
    if (typeof String.prototype.startsWith != 'function') {
        String.prototype.startsWith = function (str) {
            return this.indexOf(str) == 0;
        };
    }
 
    function OnClientKeyPressing(sender, args) {
        var keyCode = args.get_domEvent().keyCode;
        var character = String.fromCharCode(keyCode);
        if (keyCode >= 65 && keyCode <= 90) {
            sender.get_items().forEach(function (item, index) {
                if (item.get_text().startsWith(character)) {
                    item.set_checked(true);
                }
            });
            args.get_domEvent().preventDefault();
        }
        else
            args.get_domEvent().preventDefault();
    }
</script>
<telerik:RadComboBox ID="RadComboBox1" runat="server" CheckBoxes="true" AllowCustomText="true"
    OnClientKeyPressing="OnClientKeyPressing">
    <Items>
        <telerik:RadComboBoxItem Text="America" />
        <telerik:RadComboBoxItem Text="Australia" />
        <telerik:RadComboBoxItem Text="Asia" />
        <telerik:RadComboBoxItem Text="Europe" />
    </Items>
</telerik:RadComboBox>


All the best,
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.
Tags
ComboBox
Asked by
Harika
Top achievements
Rank 1
Answers by
Ivana
Telerik team
Share this question
or