[OPEN] [#136] ComboBox ForceSelection problem

Page 1 of 2 12 LastLast
  1. #1

    [OPEN] [#136] ComboBox ForceSelection problem

    Hi all,

    I have a problem when loading a combobox.
    The problem is that when I use the ForceSelection="true", the value does not load into the combo.
    When removing the ForceSelection="true", the value appears in the combo

    Please find below a sample
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <!DOCTYPE html>
    <html>
    <head id="Head1" runat="server">
        <title>Ajax Linked Combos - Ext.NET Examples</title>
        <script runat="server">
            protected void Page_Load(object sender, EventArgs e)
            {
                object[] typeOfActivitiesList = new object[]
                {
                    new object[] { 1, "type1" },
                    new object[] { 2, "type2" },
                    new object[] { 3, "type3" },
                    new object[] { 4, "type4" },
                    new object[] { 5, "type5" }
                 };
                this.storeTypeOfActivity.DataSource = typeOfActivitiesList;
                this.storeTypeOfActivity.DataBind();
                this.ComboBox1.Value = 1;
                this.ComboBox2.Value = 1;
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <ext:ResourceManager ID="ResourceManager1" runat="server">
            </ext:ResourceManager>
            <ext:Store ID="storeTypeOfActivity" runat="server">
                <Model>
                    <ext:Model ID="modelTypeOfActivity" runat="server">
                        <Fields>
                            <ext:ModelField Name="getId" Type="Int" />
                            <ext:ModelField Name="getName" Type="String" />
                        </Fields>
                    </ext:Model>
                </Model>
            </ext:Store>
            <ext:ComboBox LabelWidth="200" runat="server" ID="ComboBox1" Width="300" FieldLabel="Combo 1 ( ForceSelection=false)"
                LabelAlign="Right" LabelSeparator=" " AllowBlank="false" DisplayField="getName"
                ValueField="getId" StoreID="storeTypeOfActivity" QueryMode="Local" MatchFieldWidth="false">
            </ext:ComboBox>
            <ext:ComboBox LabelWidth="200" runat="server" ID="ComboBox2" Width="300" FieldLabel="Combo 1 ( ForceSelection=true)"
                LabelAlign="Right" LabelSeparator=" " AllowBlank="false" DisplayField="getName"
                ValueField="getId" StoreID="storeTypeOfActivity" QueryMode="Local" MatchFieldWidth="false"
                ForceSelection="true">
            </ext:ComboBox>
        </div>
        </form>
    </body>
    </html>

    Any help is appreciated,
    Thanks.
    Last edited by Daniil; Jan 24, 2013 at 2:46 PM. Reason: [OPEN] [#136]
  2. #2
    Hi @FpNetWorth,

    It looks a bug. I reported to Sencha.
    http://www.sencha.com/forum/showthread.php?254742

    For now, I can suggest to try to set up an initial value if the Store's Load event.
  3. #3
    Sencha opened a bug.

    We created an Issue to track.
    https://github.com/extnet/Ext.NET/issues/136
  4. #4
    Quote Originally Posted by Daniil View Post
    Sencha opened a bug.

    We created an Issue to track.
    https://github.com/extnet/Ext.NET/issues/136
    Thank you Daniil for your efforts,
    Hope that it will be fixed soon!
  5. #5

    Temporary Workaround for ForceSelection ComboBox Problem

    Hi,

    I have the exact same issue, though I think I have found an easy workaround for the time being.
    Just remove ForceSelection from ComboBox and stick it into AfterRender listener.
    Seems to populate my value I set in Page_Load and ForceSelection still works.

                
    <Listeners>
       <AfterRender Handler="this.forceSelection = true;" />
    </Listeners>
    Thanks,
    ltctech
  6. #6
    Hi @ltctech,

    I think it is a good workaround. Thank you for sharing!
  7. #7
    Quote Originally Posted by ltctech View Post
    Hi,

    I have the exact same issue, though I think I have found an easy workaround for the time being.
    Just remove ForceSelection from ComboBox and stick it into AfterRender listener.
    Seems to populate my value I set in Page_Load and ForceSelection still works.

                
    <Listeners>
       <AfterRender Handler="this.forceSelection = true;" />
    </Listeners>
    Thanks,
    ltctech
    Thank you @ltctech.
    It's a good idea.
    I'll try it.
  8. #8
    There is an additional side effect to setting ComboBox Value from Page_Load in 2.1.1.

    If the Value set at Page_Load is not changed before postback, it will only postback the ComboBox's text (verified with FireBug).
    In result, the server side Value will be populated with the text instead of the value.

    If the Value is changed before postback by the user by selecting something else on client side, it will postback state with the json ListItem.
    In this case the server side value is correct.

    I switched my ComboBoxes to SimpleSubmit="true" and it appears to avoid this problem.
    It essentially forces the Value to be sent in _ControlID_state param alone.
    Has its own side effect in that SelectedItem.Text is now the same as SelectedItem.Value, even though _ControlID param had the text.
  9. #9
    Figured out a different way of setting value that works regardless of ForceSelection attribute.
    More importantly, it does postback fine too with SelectedItem working as expected.

    Add this extension method to a static utility class and it just works:
            public static void SetValueAfterLoad(this Ext.Net.ComboBox combo, object value)
            {
                combo.Listeners.AfterRender.Handler = string.Format("this.store.on('load', function(){{ this.setValue({0}); }}, this)", value);
            }
    In essence, it registers with the ComboBox's store load event, and when the load event fires it goes ahead and sets the value in the ComboBox.
    Something tells me there is a race condition with store load in ExtJS as calling setValue right after rendering causes an incomplete postback.
  10. #10
    Or this way, attaching directly to store without afterrender of combo:
            public static void SetValueAfterLoad(this Ext.Net.ComboBox combo, object value)
            {
                combo.GetStore().Listeners.Load.Handler = string.Format("#{{{0}}}.setValue({1});", combo.ID, value);
            }
Page 1 of 2 12 LastLast

Similar Threads

  1. Combobox with forceselection and loadRecord
    By nukarsoft in forum 2.x Help
    Replies: 0
    Last Post: Jan 07, 2013, 2:38 PM
  2. [0.8.1] Combo with ForceSelection
    By sidinwillis in forum 1.x Help
    Replies: 6
    Last Post: Dec 22, 2009, 10:25 AM
  3. [CLOSED] ComboBox ForceSelection=False and Change Event
    By Steve in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: May 13, 2009, 2:48 AM
  4. [CLOSED] What does ForceSelection do in ComboBox?
    By harafeh in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Mar 16, 2009, 1:48 PM
  5. ForceSelection on Combo not working
    By jeybonnet in forum Bugs
    Replies: 2
    Last Post: Feb 01, 2009, 12:24 PM

Posting Permissions