[CLOSED] Why does combobox text get overwritten by the value while I set the selected item text?

Page 1 of 2 12 LastLast
  1. #1

    [CLOSED] Why does combobox text get overwritten by the value while I set the selected item text?

    I have a combobox which allows me to choose a country. Its value is an ID. The item that is selected by default is set using the SelectedItem node (I do that because the lookup store is not autoloading so the country name is not available until the combobox is expanded).

    However, the combobox text gets overwritten by the ID after the main store (from which the combobox gets the selected country ID) is loaded. How do I fix that?

        <ext:ComboBox ID="BillingAddressCountryComboBox" runat="server" StoreID="CountryLookupStore" HiddenName="BillingAddressCountryId" DataIndex="BillingAddressCountryId" DisplayField="Name" ValueField="Id" ItemSelector="div.combo-search-item">
            <Template runat="server">
                <Html>
                    <tpl for=".">
                        <div class="combo-search-item">
                            <div class="name">{Name}
    
                        
    
                    </tpl>
                </Html>
            </Template>
            <SelectedItem Text='<%# Model.BillingAddressCountryName %>' AutoDataBind="true" />
        </ext:ComboBox>

  2. #2

    RE: Why does combobox text get overwritten by the value while I set the selected item text?

    Hi,

    You cannot select an item by text, only by value. The Text property of the SelectedItem is should be using for reading only (submitted selected item reading)
  3. #3

    RE: Why does combobox text get overwritten by the value while I set the selected item text?

    So that means a combobox cannot be used practically with a non-autoloading store? Because my store is not loaded yet, when I set the value, the combobox cannot find the text that represents to the value. How else would I tell it the text to display? An ID is not very pretty...
  4. #4

    RE: Why does combobox text get overwritten by the value while I set the selected item text?

    Hi,

    If no data then selection cannot be set (because mapping value-text cannot be performed), combo doesn't support mode without a data.


    Try to add one fake ListItem to the Items collection of the combo. ListItem should contains required value and text. After the store loading that fake item will be deleted automatically
  5. #5

    RE: Why does combobox text get overwritten by the value while I set the selected item text?

    OK, thanks. I've followed your advice but I still have the problem of the combobox text being overwritten by the ID.

    I figured that stopping the combobox from being bound to the form store would make things work. After all, the binding is not necessary because the fake item already puts the correct value (the currently selected country ID) in the combobox.

    I removed the DataIndex attribute to stop the binding but it still was binding to my surprise. I found out that the store also binds using the HiddenName attribute, which had the same value as I had on the DataIndex attribute.

    How can I stop the binding without changing the HiddenName attribute? I can think of a few ugly tricks but I really want to do things properly.
  6. #6

    RE: Why does combobox text get overwritten by the value while I set the selected item text?

    Hi,

    If you don't want bind the field then bind data without that control value


    Can you demonstrate an example which shows what you described above?
  7. #7

    RE: Why does combobox text get overwritten by the value while I set the selected item text?

    I think everything that is involved, is in this markup:

            <ext:Store ID="DetailsStore" runat="server">
                <Proxy>
                    <ext:HttpProxy Method="GET" Url="/Companies/CompanyData" />
                </Proxy>
                <Reader>
                    <ext:JsonReader Root="data">
                        <Fields>
                            <ext:RecordField Name="Id" />
                            <ext:RecordField Name="ParentCompanyId" />
                        </Fields>
                    </ext:JsonReader>
                </Reader>
                <AutoLoadParams>
                    <ext:Parameter Name="companyId" AutoDataBind="true" Value='<%# Model.CompanyId %>' />
                </AutoLoadParams>
            </ext:Store>
            <ext:Store ID="ParentCompanyLookupStore" runat="server" AutoLoad="false">
                <Proxy>
                    <ext:HttpProxy Method="GET" Url="/Data/Lookup/Companies" />
                </Proxy>
                <Reader>
                    <ext:JsonReader Root="data">
                        <Fields>
                            <ext:RecordField Name="Id" />
                            <ext:RecordField Name="Name" />
                        </Fields>
                    </ext:JsonReader>
                </Reader>
            </ext:Store>
            <ext:FormPanel ID="DetailsFormPanel" runat="server" Url="/Companies/SaveCompany">
                <Items>
                    <ext:TabPanel runat="server" Border="false">
                        <Items>
                            <ext:Panel runat="server" Border="False">
                                <Items>
                                    <ext:FormLayout runat="server">
                                        <Anchors>
                                            <ext:Anchor>
                                                <Items>
                                                    <ext:Panel runat="server" FormGroup="true">
                                                        <Items>
                                                            <ext:FormLayout runat="server">
                                                                <Anchors>
                                                                    <ext:Anchor>
                                                                        <ext:ComboBox ID="ParentCompanyComboBox" runat="server" StoreID="ParentCompanyLookupStore" HiddenName="ParentCompanyId" DisplayField="Name" ValueField="Id" ItemSelector="div.combo-search-item" TriggerAction="All">
                                                                            <Template runat="server">
                                                                                <Html>
                                                                                    <tpl for=".">
                                                                                        <div class="combo-search-item">
                                                                                            <div class="name">{Name}
    
                                                                                        
    
                                                                                    </tpl>
                                                                                </Html>
                                                                            </Template>
                                                                            <Items>
                                                                                <ext:ListItem runat="server" Text='<%# Model.ParentCompanyName %>' Value="123" AutoDataBind="true" />
                                                                            </Items>
                                                                        </ext:ComboBox>
                                                                    </ext:Anchor>
                                                                </Anchors>
                                                            </ext:FormLayout>
                                                        </Items>
                                                    </ext:Panel>
                                                </Items>
                                            </ext:Anchor>
                                        </Anchors>
                                    </ext:FormLayout>
                                </Items>
                            </ext:Panel>                        
                        </Items>
                    </ext:TabPanel>
                </Items>
            </ext:FormPanel>
  8. #8

    RE: Why does combobox text get overwritten by the value while I set the selected item text?

    Hi,

    I am more interested the binding issue. Just I am not sure that clear understood your problem with combo's binding. Can you provide more details about that problem (if you can with simple example)? Sorry for many questions, just want to understand whole picture
  9. #9

    RE: Why does combobox text get overwritten by the value while I set the selected item text?

    Hi Vlad,

    Questions are fine, I like questions :)
    Here's a test project. Click on the 'Child' button on the toolbar to load the Child.ascx view that demonstrates the problem. Can you modify it to have the combobox show 'Item 2' after loading instead of '2'?

    P.S. the store items are appended to the combobox so they don't overwrite the fake item. How can I have the fake item be overwritten?

    Thanks
  10. #10

    RE: Why does combobox text get overwritten by the value while I set the selected item text?

    Hi,

    Forget about fake item, I need review merge mode (store and inner items)
    Add the following listener to the combo
    <AfterRender Handler="this.store.addRecord({Name: 'Item 2', Id: 2});this.store.commitChanges();" />
Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 6
    Last Post: Feb 26, 2014, 9:59 AM
  2. Replies: 3
    Last Post: Oct 27, 2012, 10:47 AM
  3. Replies: 1
    Last Post: Mar 05, 2012, 8:59 AM
  4. [CLOSED] Change combobox item text
    By jchau in forum 1.x Legacy Premium Help
    Replies: 6
    Last Post: Jan 25, 2011, 1:20 PM
  5. Replies: 1
    Last Post: Jan 27, 2010, 12:19 PM

Posting Permissions