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

Suppress Displayed Text in Textbox on Checkbox Checking

3 Answers 99 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Rob
Top achievements
Rank 1
Rob asked on 03 Feb 2015, 07:02 PM
Support,

I have the following RadComboBox defined.  It is populated on Page_Load().  Each item in the RadComboBox has a checkbox, because of the CheckBoxes="true" setting. 

<telerik:RadComboBox ID="cmboTest" runat="server" AllowCustomText="true" CheckBoxes="true" ShowDropDownOnTextboxClick="false" Skin="Outlook" Width="520" Height="250" MarkFirstMatch="False" NoWrap="true" OffsetX="-2" OffsetY="-2">
</telerik:RadComboBox>

Each time an item is checked, the text displayed in the textbox changes to match the current selection(s).  Since I'm allowing custom text, I don't want my custom text wiped out by the checked items.  If no custom text has been entered, I'd like to customize the message that gets displayed in the textbox.

Is there a way to accomplish these requirements?

Thanks,
Rob

3 Answers, 1 is accepted

Sort by
0
Nencho
Telerik team
answered on 06 Feb 2015, 09:48 AM
Hello Rob,

I can suggest you to overwrite the private function, which is responsible for the text update of the RadCombobox, when a checkbox is checked. However, please keep in mind that allowing custom text in a CheckBox scenario is a not supported scenario and unexpected behavior may arise.

Please consider adding the following function :

<script type="text/javascript">
       var $T = Telerik.Web.UI;
 
       $T.RadComboBox.prototype._updateComboBoxText = function () {
           if (!this._checkBoxes || this._text != "") {
               return;
           }
           var text = "",
               items = this.get_items(),
               itemsCount = items.get_count(),
               localization = this.get_localization();
 
           for (var i = 0, length = this.get_checkedIndices().length; i < length; i++) {
               var item = this._children.getItem(this._checkedIndices[i]);
               text += item.get_text() + ", ";
           }
 
           var checkedItemTexts = text.replace(/,$/, "");
           checkedItemTexts = checkedItemTexts.substring(0, checkedItemTexts.length - 2);
 
           if (this._checkedIndices.length == itemsCount && itemsCount > 0 &&
               this._checkedItemsTexts == $T.RadComboBoxCheckedItemsTexts.FitInInput) {
               this.set_text(localization.AllItemsCheckedString);
           } else if (this._checkedItemsTexts == $T.RadComboBoxCheckedItemsTexts.FitInInput &&
               this._checkedIndices.length > 1 &&
               !this._checkedItemsTextsFitInputWidth(checkedItemTexts)) {
               this._checkedItemsTextOverflows = true;
               this.set_text(this._checkedIndices.length + " " + localization.ItemsCheckedString);
           } else if (itemsCount === 0 || this._checkedIndices.length === 0) {
               this.set_text("");
           } else {
               this._checkedItemsTextOverflows = false;
               this.set_text(checkedItemTexts);
           }
       }
   </script>

Hope this would help.

Regards,
Nencho
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Rob
Top achievements
Rank 1
answered on 06 Feb 2015, 04:03 PM
Nencho,

I was able to customize this function to meet 99% of the requirements.  Thank you!

Next question, what would be the best client side event(s) to determine that the inputbox of the RadComboBox has just had it's text cleared?  The user could backspace or delete key to clear the text or the X on the far right could be clicked.  What would be the best client side event(s) to check for the text being cleared?

Thanks,
Rob
0
Nencho
Telerik team
answered on 11 Feb 2015, 01:01 PM
Hello Rob,

For such scenario, we recommend to use the OnClientTextChanged client-side event of the RadComboBox. For more information, please refer to the following documentation article:

http://www.telerik.com/help/aspnet-ajax/combobox-onclienttextchange.html

Regards,
Nencho
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
ComboBox
Asked by
Rob
Top achievements
Rank 1
Answers by
Nencho
Telerik team
Rob
Top achievements
Rank 1
Share this question
or