[CLOSED] CheckBoxGroup initial state

  1. #1

    [CLOSED] CheckBoxGroup initial state

    Below is a sample I put together to discuss the CheckBoxGroup CheckItems. After your helped in the previous thread, I now have the following question.

    If I push the 'Get Count' button the answer is 0
    If I select the Calendar button to show the years selected and then push the 'Get Count' button the answer is 1.

    Shouldn't the initial answer also be 1 instead of 0?

    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <script runat="server">
        protected void GetCheckedItemsCount(object sender, DirectEventArgs e)
        {
            CheckboxGroup group = X.GetCmp<CheckboxGroup>("CheckboxGroup1");
            for (var i = 0; i < group.CheckedItems.Count; i++)
            {
                X.Msg.Alert("Item Selected", group.CheckedItems[i]).Show();
            }
            X.Msg.Alert("DirectEvent", group.CheckedItems.Count).Show();
        }
    
        protected void CheckBoxChange(object sender, DirectEventArgs e)
        {
            CheckboxGroup group = X.GetCmp<CheckboxGroup>("CheckboxGroup1");
            string strYears = "";
            for (var i = 0; i < group.CheckedItems.Count; i++)
            {
                strYears = strYears + group.CheckedItems[i].RawValue + " ";
            }
            X.Msg.Alert("CheckBox Change", strYears).Show();
        }
        
    </script>
    <!DOCTYPE html>
    <html>
    <head id="Head1" runat="server">
        <title>Ext.NET v2 Example</title>
    </head>
    <body>
        <form runat="server">
        <ext:ResourceManager runat="server" />
        <ext:Panel runat="server" Title="Charts" Icon="ChartBar" Region="South" Height="240"
            Split="true" Collapsible="true" Layout="BorderLayout">
            <DockedItems>
                <ext:Toolbar runat="server" Dock="Left" Vertical="true">
                    <HtmlBin>
                    </HtmlBin>
                    <Items>
                        <ext:Button runat="server" ToolTip="Years" Icon="Calendar" ArrowAlign="Right" MenuAlign="tl-tr">
                            <Menu>
                                <ext:Menu runat="server" Title="Request Years" TitleAlign="Center" ShowSeparator="false"
                                    RenderToForm="true">
                                    <Items>
                                        <ext:CheckboxGroup ID="CheckboxGroup1" runat="server" OnDirectChange="CheckBoxChange"
                                            ColumnsWidths="70,70">
                                            <Items>
                                                <ext:Checkbox runat="server" Name="year1" BoxLabel="2012" InputValue="2012" Checked="true" />
                                                <ext:Checkbox runat="server" Name="year2" BoxLabel="2011" InputValue="2011" />
                                                <ext:Checkbox runat="server" Name="year3" BoxLabel="2010" InputValue="2010" />
                                                <ext:Checkbox runat="server" Name="year4" BoxLabel="2009" InputValue="2009" />
                                                <ext:Checkbox runat="server" Name="year5" BoxLabel="2008" InputValue="2008" />
                                                <ext:Checkbox runat="server" Name="year6" BoxLabel="2007" InputValue="2007" />
                                                <ext:MenuSeparator runat="server" />
                                                <ext:MenuSeparator runat="server" />
                                                <ext:Button runat="server" Text="Select All">
                                                    <Listeners>
                                                        <Click Handler="#{CheckboxGroup1}.setValue({ year: true })" />
                                                    </Listeners>
                                                </ext:Button>
                                                <ext:Button ID="Button1" runat="server" Text="Deselect All">
                                                    <Listeners>
                                                        <Click Handler="#{CheckboxGroup1}.setValue({})" />
                                                    </Listeners>
                                                </ext:Button>
                                            </Items>
                                        </ext:CheckboxGroup>
                                    </Items>
                                </ext:Menu>
                            </Menu>
                        </ext:Button>
                        <ext:Button runat="server" Text="Get Count" OnDirectClick="GetCheckedItemsCount" />
                    </Items>
                </ext:Toolbar>
            </DockedItems>
        </ext:Panel>
        </form>
    </body>
    </html>
    Last edited by Daniil; Nov 06, 2012 at 7:22 AM. Reason: [CLOSED]
  2. #2
    Hi Chris,

    A problem is a fact that a Button's Menu and, respectively, its items (a CheckboxGroup in your case) are not rendered by default. It is rendered on click.

    Therefore no submit before click.

    You could send a required data via a DirectEvent's ExtraParams collection. But I would prefer to use this trick to force rendering.
    <AfterRender Handler="this.showMenu(); this.hideMenu();" />
    It is a Button's listener.
  3. #3
    You got me around an issue again. Thank you. Go ahead and close this thread.

Similar Threads

  1. [CLOSED] Initial value Datepicker
    By CarWise in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Nov 11, 2011, 3:25 PM
  2. [CLOSED] Reset GridPanel columns to initial state
    By jmcantrell in forum 1.x Legacy Premium Help
    Replies: 12
    Last Post: Jul 18, 2011, 6:21 PM
  3. Accordion Layout initial state
    By dcrysler in forum 1.x Help
    Replies: 1
    Last Post: Jul 15, 2011, 9:53 PM
  4. How to maintain state of Checkboxgroup
    By Jamishra in forum 1.x Help
    Replies: 0
    Last Post: Nov 19, 2009, 1:01 PM
  5. Replies: 0
    Last Post: Jun 23, 2009, 9:31 AM

Posting Permissions