Suppress Displayed Text in Textbox on Checkbox Checking

4 posts, 0 answers
  1. Rob
    Rob avatar
    115 posts
    Member since:
    Aug 2012

    Posted 03 Feb 2015 Link to this post

    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
  2. Nencho
    Admin
    Nencho avatar
    1457 posts

    Posted 06 Feb 2015 Link to this post

    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.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Rob
    Rob avatar
    115 posts
    Member since:
    Aug 2012

    Posted 06 Feb 2015 in reply to Nencho Link to this post

    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
  5. Nencho
    Admin
    Nencho avatar
    1457 posts

    Posted 11 Feb 2015 Link to this post

    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.

     
Back to Top