[FIXED] [V0.7.0] ComboBox Bug

Page 1 of 2 12 LastLast
  1. #1

    [FIXED] [V0.7.0] ComboBox Bug

    Hello,

    If you run the below example, you will notice a minor error in the SelectedIndex property.

    Example.aspx:
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <script runat="server">
        protected void Button1_Click(object sender, EventArgs e)
        {
            Label1.Text = String.Format("{0} is index: {1}", ComboBox2.SelectedItem.Text, ComboBox2.SelectedIndex);
        }
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>Example</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="True" />
        <ext:ScriptManager ID="ScriptManager2" runat="server" ScriptMode="Debug" />
        <ext:ComboBox ID="ComboBox1"
            runat="server"
            EmptyText="----"
            Width="255">
            <Items>
                <ext:ListItem Text="Canada" Value="CA" />
                <ext:ListItem Text="United States" Value="USA" />
            </Items>
            <Listeners>
                <Select Handler="#{ComboBox2}.clearValue();" />
            </Listeners>
        </ext:ComboBox>
        <ext:ComboBox ID="ComboBox2"
            runat="server"
            EmptyText="----"
            Width="255">
            <Items>
                <ext:ListItem Text="Ontario" Value="ON" />
                <ext:ListItem Text="Quebec" Value="QC" />
            </Items>
        </ext:ComboBox>
        <ext:Button ID="Button1" runat="server" AutoPostBack="True" &#111;nclick="Button1_Click" Text="Submit">
            <Listeners>
                <Click Handler="#{ComboBox2}.setValue('QC');" />
            </Listeners>
        </ext:Button>
        <ext:Label ID="Label1" runat="server" Text="Waiting ..." />
        </form>
    </body>
    </html>
    Replication steps:

    1. Load page
    2. Select 'Canada' from ComboBox1
    3. Select 'Ontario' from ComboBox2
    4. Click 'Submit', notice it changed to 'Quebec' on ComboBox2? (on purpose)
    5. Notice the result says index = 0 (Ontario) when Quebec is selected (wrong)

    Cheers,
    Timothy
  2. #2

    RE: [FIXED] [V0.7.0] ComboBox Bug

    Hi Timothy,

    Please note that setValue function of ComboBox doesn't fire Select event, so the hidden field for index doesn't updated.
    If you replace #{ComboBox2}.setValue('QC');

    By
    #{ComboBox2}.setValueEx('QC');

    then this example should works properly (setValueEx firing Select event)


  3. #3

    RE: [FIXED] [V0.7.0] ComboBox Bug

    Why not make the .setValue function run the select ? What possible scenario would someone want to set the value of the ComboBox without selecting if it's in local mode?

    Cheers,
    Timothy
  4. #4

    RE: [FIXED] [V0.7.0] ComboBox Bug

    It is original ExtJS behaviour. Especially for such cases we added setValueEx. May be there is a reason why ExtJS Team did so, not otherwise

    We can override setValue code but it can get unexpected result (may be)

  5. #5

    RE: [FIXED] [V0.7.0] ComboBox Bug

    Thanks vlad, I appreciate that you guys put the extra throught into developing the setValueEx() function, it is useful indeed.

    Would be great if it could override the default function, would be one less thing for developers to think about.

    Thanks for your solution to the original question, and your response times (like always)

    Cheers,
    Timothy
  6. #6

    RE: [FIXED] [V0.7.0] ComboBox Bug

    #{ComboBox2}.setValueEx('QC')
    The following example demonstrates that the selectedIndex is not updated after setValueEx()

    Example.aspx:
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <script runat="server">
        protected void Button1_Click(object sender, EventArgs e)
        {
            Label1.Text = String.Format("{0} is index: {1}", ComboBox2.SelectedItem.Text, ComboBox2.SelectedIndex);
        }
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>Example</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="True" />
        <ext:ScriptManager ID="ScriptManager2" runat="server" ScriptMode="Debug" />
        <ext:ComboBox ID="ComboBox1"
            runat="server"
            EmptyText="----"
            Width="255">
            <Items>
                <ext:ListItem Text="Canada" Value="CA" />
                <ext:ListItem Text="United States" Value="USA" />
            </Items>
            <Listeners>
                <Select Handler="#{ComboBox2}.clearValue();" />
            </Listeners>
        </ext:ComboBox>
        <ext:ComboBox ID="ComboBox2"
            runat="server"
            EmptyText="----"
            Width="255">
            <Items>
                <ext:ListItem Text="Ontario" Value="ON" />
                <ext:ListItem Text="Quebec" Value="QC" />
            </Items>
        </ext:ComboBox>
        <ext:Button ID="Button2" runat="server" Text="Change to Quebec">
            <Listeners>
                <Click Handler="#{ComboBox2}.setValueEx('QC');" />
            </Listeners>
        </ext:Button>
        <ext:Button ID="Button1" runat="server" AutoPostBack="True" &#111;nclick="Button1_Click" Text="Submit">
            <Listeners>
                <Click Handler="alert(#{ComboBox2}.selectedIndex);" />
            </Listeners>
        </ext:Button>
        <ext:Label ID="Label1" runat="server" Text="Waiting ..." />
        </form>
    </body>
    </html>
    Replication steps:

    1. Load page
    2. Select 'Canada' from ComboBox1
    3. Click 'Change to Quebec'
    4. Click 'Submit' - notice the alert says -1 which should read 1

    Cheers,
    Timothy
  7. #7

    RE: [FIXED] [V0.7.0] ComboBox Bug

    The selectedIndex is private variable of ComboBox class (this variable updated only when you use select function). You should not use this variable directly.

    If you need to get selected index of combo then you can use next code
        var r = combo.findRecord(combo.valueField, combo.getValue());
        var index = combo.store.indexOf(r);
  8. #8

    RE: [FIXED] [V0.7.0] ComboBox Bug

    Vlad, you just said that the .setValueEx() fires the select function? I'm confused now.

    Cheers,
    Timothy
  9. #9

    RE: [FIXED] [V0.7.0] ComboBox Bug

    Yes, it fires the Select event but I didn't say that it updates private selectedIndex variable (the standart setValue doesn't update this field also). We must forget about selectedIndex variable, it used internally by Combobox JavaScript class only. The js ComboBox class doesn't allow to using this variable (by logic because the javascript don't have ability to forbidden access to some functions or variables like high-level languages with private, public and etc access modifiers)


  10. #10

    RE: [FIXED] [V0.7.0] ComboBox Bug



    Hi Timothy,

    I need some time to review this thread. As mentioned in a previous thread, I'm not really happy with the current functionality of the <ext:ComboBox>, so we're going to be making some changes.
    Geoffrey McGill
    Founder
Page 1 of 2 12 LastLast

Similar Threads

  1. [FIXED] [V0.7] ComboBox SelectedIndex
    By Timothy in forum Bugs
    Replies: 9
    Last Post: Aug 20, 2009, 3:19 PM
  2. [FIXED] [V0.6] ComboBox HideTrigger
    By Timothy in forum Bugs
    Replies: 6
    Last Post: Jan 22, 2009, 11:57 AM
  3. [FIXED] [V0.7] ComboBox Bug
    By Timothy in forum Bugs
    Replies: 6
    Last Post: Nov 01, 2008, 12:32 PM
  4. [FIXED] [V0.7.0] ComboBox Bug
    By Timothy in forum Bugs
    Replies: 2
    Last Post: Oct 10, 2008, 11:59 AM
  5. [FIXED] [V0.6] ComboBox
    By Timothy in forum Bugs
    Replies: 7
    Last Post: Aug 26, 2008, 2:47 PM

Posting Permissions