clearItems() not working

5 posts, 0 answers
  1. Richard M
    Richard M avatar
    15 posts
    Member since:
    Feb 2010

    Posted 15 Sep 2010 Link to this post

    function ResetCombo(combo) {
        if (combo) {
            combo.clearItems();
            combo.set_text("");
        }
    }
    function LocationSelectedIndexChanged<%= ID %>(sender, eventArgs) {
        var locationCombo = $find("<%= rcbLocation.ClientID %>");
        var addressCombo = $find("<%= rcbAddress.ClientID %>");
        var contactCombo = $find("<%= rcbContact.ClientID %>");
        var contact2Combo = $find("<%= rcbContact2.ClientID %>");
        var value = locationCombo.get_value();
        ResetCombo(addressCombo);  // Items clear on on first index change
        ResetCombo(contactCombo);
        ResetCombo(contact2Combo);
       if (contactCombo) contactCombo.disable(); 
       if (contact2Combo) contact2Combo.disable(); 
        if (value == "")
        {
            if (addressCombo) addressCombo.disable(); 
        }
        else
        {
            if (addressCombo) {
            addressCombo.enable(); 
            addressCombo.requestItems("", false); // Fires only on first time index is changed
            }
        }
    }

    When this method is called, the text does empty, but the items do no clear.  So when the combox is opened, it will not request it's items from the server, which have changed.  When the drop down location index is changed, the first time it fires all events.  Changing it again calls the methods, but clear items does not work, and request items does not fire.

    Note:  requestItems fires with "" because it is a custom implementation using context instead of the text of the combo box
  2. Cori
    Cori avatar
    562 posts
    Member since:
    Jul 2010

    Posted 15 Sep 2010 Link to this post

    Hello Richard,

    Try wrapping you ResetCombo code inside of a trackChanges()/commitChanges() block. Like so:

    function ResetCombo(combo) { 
        if (combo) { 
            combo.trackChanges();
            combo.clearItems(); 
            combo.set_text(""); 
            combo.commitChanges();
        
    }

    This way the changes are persisted to the ViewState.

    I hope that helps.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Richard M
    Richard M avatar
    15 posts
    Member since:
    Feb 2010

    Posted 15 Sep 2010 Link to this post

    That didn't solve the problem.  I was under the impression that trackchanges just made the changes available on the server side.  I only need the change to work client side.
  5. Simon
    Admin
    Simon avatar
    2281 posts

    Posted 16 Sep 2010 Link to this post

    Hello Richard Maxwell,

    Indeed, track/commit changes preserve the client-side changes so that they are available on the server.

    Still the clearItems method works fine on my side in the following setup:
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" />
        <div>
            <telerik:RadComboBox ID="RadComboBox1" runat="server">
                <Items>
                    <telerik:RadComboBoxItem Text="1" />
                    <telerik:RadComboBoxItem Text="2" />
                    <telerik:RadComboBoxItem Text="3" />
                    <telerik:RadComboBoxItem Text="4" />
                </Items>
            </telerik:RadComboBox>
        </div>
        <input type="button" id="clear" value="clear" />
        </form>
     
        <script type="text/javascript">
            (function ($) {
                $("#clear").click(function () {
                    var combo = $find("RadComboBox1");
                    combo.clearItems();
                    combo.set_text("");
                });
            })($telerik.$);
        </script>

    So most probably, there is something else going on in your implementation, which causes the issue. Could you please try putting an alert right after the clearItems call to verify the number of Items in the RadComboBox after clearing:
    function ResetCombo(combo) {
        if (combo) {
            combo.clearItems();
            alert(combo.get_items().get_count());
            combo.set_text("");
        }
    }

    Regards,
    Simon
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. Richard M
    Richard M avatar
    15 posts
    Member since:
    Feb 2010

    Posted 16 Sep 2010 Link to this post

    var randomnumber = Math.floor(Math.random() * 10001);
    addressCombo.requestItems(randomnumber, false);

    I was able to fix the problem like this.  Because I use the context to pass in the data I actually use to search, I just always left the text blank.  The problem was requestitems appears to not fire if the text is the same, so to force it to fire when I know the context items have changed, I had to make sure it got something new for text.  So I just gave it a random number, so when I tell it to update, it thinks it has a reason to.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017