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

use jQuery to disable checkboxes in RadComboBox

2 Answers 188 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Jeremy
Top achievements
Rank 1
Jeremy asked on 23 Mar 2012, 10:57 PM
I have a RadListView that has an ItemTemplate that contains a RadComboBox. As such, the IDs of the combo boxes are dynamically generated, so this will not work for me:

var rcbAssigneeObject = $find("<%=rcbAssignee.ClientID %>");


. What I'm trying to do is apply some business logic to what can and cannot be selected. I'm having trouble targetting the items in the listbox. When a check box is selected, I need to use jQuery to select all items in the combobox, then check the value of an attribute that is part of the object loaded into the datasource on page load called "type". If this type is equal to, say, "person", then I need to disable all items in the combobox other whos type is "group". I've started with something like this:

$(".AssigneeTag").find(":checkbox").click(
        function () {
            var allItems = $(this).closest(".rcbList").find(".rcbItem");
            //check item types here
    });

I'm stuck on where to go from here. I seem to be unable to access any sort of item client id in order to create an asp object that allows me to manipulate the telerik object. For instance, if I were to just grab the item like:

var myItem = $(this).closest(".rcbItem").attr("id");

it would return null for that field. And if i try to get the id of the parent above that, I also get null.

Any ideas?

Or at the very least, how do I obtain the RadComboBox item starting at the checkbox OnClick event. For instance

var rcb = $(this).pathToRadComboBoxControl().Get();

The from there, how do i iterate through the item collection. is there a method like rcb.get_items().each(...);  ??

2 Answers, 1 is accepted

Sort by
0
Jeremy
Top achievements
Rank 1
answered on 23 Mar 2012, 11:00 PM
 
0
Accepted
Kalina
Telerik team
answered on 29 Mar 2012, 08:25 AM
Hi Jeremy,

I am suggesting you a easier way to implement your business logic.
You can handle the RadComboBox OnClientItemChecked event that fires every time a checkbox is checked.
Then you can loop through combo box items and enable (or disable) them in this manner:
<script type="text/javascript">
 
    function OnClientItemChecked(sender, eventArgs) {
        var items = sender.get_items();
 
        for (i = 0; i < items.get_count(); i++) {
 
            var item = items.getItem(i);
            if (item.get_attributes().getAttribute("Type") == "someValue")
                item.set_enabled(false);
        }
    }
</script>
 
 
<telerik:RadListView ID="RadListView1" runat="server"
...
 <EditItemTemplate>
...
<telerik:RadComboBox ID="RadComboBox1" runat="server"
    CheckBoxes="true" OnClientItemChecked="OnClientItemChecked">
</telerik:RadComboBox>


Regards,
Kalina
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
Jeremy
Top achievements
Rank 1
Answers by
Jeremy
Top achievements
Rank 1
Kalina
Telerik team
Share this question
or