Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
228
Rename a dropdown item
posted

Hi,

 

In my application, I have a web tree that allows the user to change the name.  I also have a web drop down that contains a list of certain items from the tree.  I am trying to, without a postback, update the web drop down when the client changes the tree item name.  The tree item is updated via a JavaScript function that makes a call to a custom web service; and when that web service returns a 'success' state I want to update the drop down with the new item name.

 

Browning inspiration from the sample browser, I wrote this JavaScript function ...

 

 

 

function RenameDDLItem(ddlName, oItem, newName) {

    if (oItem) {

        var combo = $find(ddlName);

        if (combo) {

            var items = combo.get_items();

            for (var index = 0; index < items.get_length(); index++) {

                var item = items.getItem(index);

                if ((item.get_text() == oItem.LocationName) && (item.get_value() == String(oItem.LocationID))) {

                    combo.get_items().getItem(index).set_text(newName);

                }

            }

        }

    }

}

... that is called after the web service responds with a 'success' status.

 

I think I'm on the right track to accomplish my goal, but I either need to do something more or something is preventing me from updating the control.
My scripting does not error out, but it also doesn't rename the item in the drop down.
Any suggestions would be helpfull.
Thanks!
p.s.
I've tried the .remove(item) and .insert(index, item) methods for the item collection and it does update with the renamed value; however, it removes all of the other items from the list.
and this is the aspx code for my dropdown:
                            <ig:WebDropDown ID="wddLocations" runat="server" DropDownAnimationType="Bounce" DropDownContainerMaxHeight="85px"
                                EnableAutoFiltering="Client" EnableDropDownAsChild="False" EnableRenderingAnchors="False"
                                MultipleSelectionType="Checkbox" PageSize="0" StyleSetName="Default" Width="175px"
                                DropDownContainerHeight="85px">
                                <ClientEvents DropDownClosed="MoveCaret" ItemAdded="itemAdded" Focus="wdd_Focus" ValueChanging="wdd_ValueChanging" ValueChanged="wddLocations_ValueChanged" />
                            </ig:WebDropDown>

 

Parents
  • 24671
    Verified Answer
    posted

    Hi,

    You aren't doing anything wrong. Calling set_text(..) on the item will update its state, and on the subsequent ajax request or postback, the new markup will have the updated texts. That's because the item may have more than text, i.e. it may be a templated item with contents generated on the server, so it may not be possible to update the markup by just using innerHTML on the client-side.  If you'd like to achieve that by calling set_text directly, i suggest to add this line after call to set_text()

    item._element.innerHTML = "new text"; 

    I agree that in the simplest case, where your item has only text, it's more intuitive to have that automatically done by set_text(). I will submit an issue for that and have it fixed. 

    Thanks,

    Angel 

Reply Children
No Data