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

OnClientItemChecked and set_text issue

5 Answers 170 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Ivan
Top achievements
Rank 1
Ivan asked on 27 Nov 2013, 10:38 PM
Hello everyone, I have one problem with RadComboBox and will appreciate any help. I'm using 2013.1.403.40 version with v4.0.30319 runtime in my ASP.NET application. So, here is my solution: combobox on the page, that is populated from server side.
<telerik:radcombobox id="cmbBox" runat="server" width="185px"
DataTextField="Text" DataValueField="Value" DataCheckedField="IsChecked" MaxHeight="185px"
CheckBoxes="True" EnableCheckAllItemsCheckBox="True" Filter="None" Sort="None" EnableTextSelection="False" OnClientItemChecked="cmbBoxItemChecked"/>
cmbBox.Items.Add(new RadComboBoxItem("separator1") { IsSeparator = true });
cmbBox.Items.Add(new RadComboBoxItem
                    {  Text = "Name1",   Value = "Value1",  Checked = false });
cmbBox.Items.Add(new RadComboBoxItem("separator2") { IsSeparator = true });
cmbBox.Items.Add(new RadComboBoxItem
                    {  Text = "Name2",   Value = "Value2",  Checked = false });
cmbBox.Items.Add(new RadComboBoxItem("separator3") { IsSeparator = true });
cmbBox.Items.Add(new RadComboBoxItem
                    {  Text = "Name3",   Value = "Value3",  Checked = false });
So, 6 items will appear on client side (3 separators and 3 simple items). I've also attached event handler for OnClientItemChecked with folowing logic:

function cmbBoxItemChecked(sender, eventArgs)
{
   sender.set_text("my custom text according to internal logic, based on checked item");
}
And here is my problem: for example, before sender.set_text operation, text was "2 items checked". Right after sender.set_text it will change to "my custom..." (as desired).
But after exiting from event handler, text will return to it's previous state ("2 items checked"). It seems, that another event fires right after 
OnClientItemChecked.
So my desired behaviour, is to change text in radcombobox after user was (un)checked random item. It is possible, or by now, this is not achievable ? 
Thank you in advance.

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 28 Nov 2013, 04:46 AM
Hi Ivan,

Please have a look into the following JavaScript to set a text on OnClientItemChecked event.

JavaScript:
<script type="text/javascript">
    function cmbBoxItemChecked(sender, eventArgs) {
        if (eventArgs.get_item()._checkBoxElement.checked == true) {
            sender.set_text("my custom text according to internal logic, based on checked item");
            sender.ClearSelection();
        }
    }
</script>

Thanks,
Shinu.
0
Ivan
Top achievements
Rank 1
answered on 28 Nov 2013, 10:26 AM
Hi Shinu, many thanks for you quick answer. Unfortunately, this did not work. This clearselection method do not prevent text changes AFTER event has ended. For example, 
//initial text "2 items checked"
alert(sender.get_text()); // "2 items checked"
sender.set_text("test");
alert(sender.get_text()); // "test"
sender.clearSelection();
alert(sender.get_text()); "empty message" and all selection is cleared, which i did not prefer to do, BTW
}
// event handler ended and text again returned to "2 items checked"
Maybe there are another ways to do this ? Maybe with native js and DOM ?
Thank you.
0
Nencho
Telerik team
answered on 02 Dec 2013, 04:31 PM
Hello Ivan,

Please consider setting an appropriate time out for the execution of the desired text editing in the following manner:
function cmbBoxItemChecked(sender) {
           setTimeout(function (e) {
               sender.set_text("my custom text according to internal logic, based on checked item");
           }, 10)
       }


Regards,
Nencho
Telerik
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 the blog feed now.
0
Ivan
Top achievements
Rank 1
answered on 02 Dec 2013, 05:18 PM
Thank you for advice. Actually, I've also applied this solution, because there is no another good alternative. However, I think this is workaround, because timeout may behave differently on all browsers, and if user will quickly recheck items, there will be visible UI changes and freezes. Maybe, Telerik team should consider to implement event for this purpose, for example, after text actually was changed in header. Existing OnClientTextChange do not fit for this purpose. And i think, there is a bug in implementation. If we have both OnClientItemChecking and OnClientItemChecked it's seems logical, that on "ed" event all actions were already performed by control, but it is not.
Anyway, thanks again, and I will hope this will help anyone who will face the same problem.

0
Nencho
Telerik team
answered on 05 Dec 2013, 09:43 AM
Hello Ivan,

Regarding your implementation of the RadComboBox and the fact that the CheckBoxes feature is enabled the control is in read-only state. In such scenario altering the text of the input of the control is  consider as hack, since it should correspond to the checked items text. This is the reason for the provided workaround.

Regards,
Nencho
Telerik
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 the blog feed now.
Tags
ComboBox
Asked by
Ivan
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Ivan
Top achievements
Rank 1
Nencho
Telerik team
Share this question
or