[CLOSED] Add checkbox to checkboxgroup during runtime

Page 2 of 5 FirstFirst 1234 ... LastLast
  1. #11
    One more thing... how do i set the Checked property to true or false in the javascript method (example you provided)?

    Sorry for keep bugging you, but we need to have this page done yesterday and I'm in a bind right now. Many thanks for your help. :-)
  2. #12
    Quote Originally Posted by dnguyen View Post
    One more thing... how do i set the Checked property to true or false in the javascript method (example you provided)?
    Just add the "checked : true" property in config.

    Example
    cfg.items.push({
        id: checkBoxId,
        xtype: "checkbox",
        inputValue: checkBoxId,
        boxLabel: checkBoxId,
        checked: true
    });
  3. #13
    Quote Originally Posted by dnguyen View Post

    I notice usring Group1.Items.Clear() does not clear out the previous checkboxes. Do you have any recommendation on how to remove existing checkboxes from checboxgroup using either javascript or serverside code?
    Well, CheckboxGroup doesn't support removing checkboxes on the fly.

    As a workaround I can suggest you to clear items collection before adding new checkboxes, see //added comment:

    Example
    var addCheckboxTo = function(groupId, checkBoxId) {
        var group = Ext.getCmp(groupId),
            cfg = group.initialConfig;
        cfg.items = []; //added
        cfg.items.push({
            id: checkBoxId,
            xtype: "checkbox",
            inputValue: checkBoxId,
            boxLabel: checkBoxId,
            checked: true
        });
        group.destroy();
        new Ext.form.CheckboxGroup(cfg);
    }
  4. #14
    Hi Daniil,

    Thanks for the suggestion. The line cfg.items = []; //added removes checkboxes as you suggested. However, when I call the function from a loop (i.e. foreach loop), it would remove all items except for the last item. I'd like to be able to add/remove more than one checkboxes at a time. This is due to the user selection and pulling data from database to populate checkboxgroup. Is it possible?

    Thanks,
    Daniel
  5. #15
    Well, I would suggest you to change js function code to apply array of checkboxes ids.

    It can look something like this:

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    
    <script runat="server">
        private static int counter = 1;
    
        protected void AddCheckbox(object sender, AjaxEventArgs e)
        {
            string[] checkboxIds = 
            { 
                "NewCheckbox" + counter++, 
                "NewCheckbox" + counter++, 
                "NewCheckbox" + counter++ 
            };
            string jsonCheckboxIds = JSON.Serialize(checkboxIds);
            ScriptManager.GetInstance(this.Context).AddScript("addCheckboxTo('{0}', '{1}')", "Group1", jsonCheckboxIds);
        }   
    </script>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Coolite 0.8.X Example</title>
    
        <script type="text/javascript">
            var counter = 1;
    
            var addCheckboxTo = function(groupId, checkBoxIds) {
                var group = Ext.getCmp(groupId),
                    cfg = group.initialConfig;
                cfg.items = [];
                checkBoxIds = eval(checkBoxIds);
                for (var i = 0; i < checkBoxIds.length; i++) {
                    cfg.items.push({
                        id: checkBoxIds[i],
                        xtype: "checkbox",
                        inputValue: checkBoxIds[i],
                        boxLabel: checkBoxIds[i]
                    });
                }
                group.destroy();
                new Ext.form.CheckboxGroup(cfg);
            }
        </script>
    
    </head>
    <body>
        <form runat="server">
        <ext:ScriptManager runat="server" />
        <ext:CheckboxGroup ID="Group1" runat="server" ColumnsNumber="1">
            <Items>
                <ext:Checkbox runat="server" BoxLabel="Checkbox 1" />
                <ext:Checkbox runat="server" BoxLabel="Checkbox 2" />
            </Items>
        </ext:CheckboxGroup>
        <ext:Button runat="server" Text="Add checkbox">
            <AjaxEvents>
                <Click OnEvent="AddCheckbox" />
            </AjaxEvents>
        </ext:Button>
        </form>
    </body>
    </html>
  6. #16
    Hi Daniil,

    Your example works great. However, I have a question. Will this only work with the Ajax event? Here's the reason for the question.

    One of our page have a similar layout as your demo under GridPanel ->Miscellaneous ->Details_Window. When the user click on the Details cell, the window with details pops up. One of the columns have multiple fields, which will be displayed as checkboxes. So what i did was to hookup the cellclick listener to open the window and fill window fields with data from the selected row of the gridpanel. The example you provided will populate the checkboxes the first time, but I'd have to comment out the line cfg.items = []. After that, it will display the same checkboxes values.

    I'm pulling my hair out on this one and really need you guys help on this. Thanks in advance for your help.

    Dan
  7. #17
    One more thing. If I add the line cfg.items = [], then it will just display a blank checkbox group without any updated checkboxes. Not sure why.
  8. #18
    Quote Originally Posted by dnguyen View Post
    Hi Daniil,

    Your example works great. However, I have a question. Will this only work with the Ajax event? Here's the reason for the question.

    One of our page have a similar layout as your demo under GridPanel ->Miscellaneous ->Details_Window. When the user click on the Details cell, the window with details pops up. One of the columns have multiple fields, which will be displayed as checkboxes. So what i did was to hookup the cellclick listener to open the window and fill window fields with data from the selected row of the gridpanel. The example you provided will populate the checkboxes the first time, but I'd have to comment out the line cfg.items = []. After that, it will display the same checkboxes values.
    Well, probably, it's possible to get this code working not with AjaxEvent only. Where are trying this code?

    It would be best to provide us with a full (but simplified) .aspx page to reproduce the issue.
  9. #19
    Hi Daniil,

    Here's the mockup window that will display all fields in separate tabs (including the tab with checkboxes). I wonder the reason the line new Ext.form.CheckboxGroup(cfg); does not work due to the nesting of the checkboxes tab. Thanks for your help.

    <ext:Window 
                            ID="EmployeeDetailsWindow" 
                            runat="server" 
                            Icon="Group" 
                            Title="Employee Details" 
                            Width="650" 
                            Height="450" 
                            AutoShow="false" 
                            Modal="true"
                            ShowOnLoad="false">
                            <Body>    
                                <ext:FitLayout ID="FitLayout1" runat="server">
                                    <ext:TabPanel ID="TabPanel1" runat="server" ActiveTabIndex="0" Border="false">
                                        <TopBar>
                                            <ext:Toolbar ID="Toolbar1" runat="server">
                                                <Items>
                                                <ext:Label ID="Label1" runat="server" Text="Facility:" StyleSpec="padding: 0px 68px 0px 5px"></ext:Label>
                                                <ext:ComboBox 
                                                    ID="cbFacility"
                                                    runat="server" 
                                                    StoreID="Facility_Store"
                                                    FieldLabel="Facility" 
                                                    AllowBlank="true"
                                                    DisplayField="text"
                                                    ValueField="id"
                                                    TypeAhead="true" 
                                                    Mode="Local"
                                                    ForceSelection="true"
                                                    TriggerAction="All"
                                                    EmptyText="Select Facility..."
                                                    Width="250">
                                                    <%--<AjaxEvents>
                                                        <Select OnEvent=""></Select>
                                                    </AjaxEvents>--%>
                                                    <Items>
                                                        <ext:ListItem Text="All Facilities" Value="All Facilities" />
                                                    </Items>
                                                    </ext:ComboBox>                     
                                                </Items>
                                    </ext:Toolbar>
                                        </TopBar>
                                        <Tabs>
                                            <ext:Tab 
                                                ID="StatusNotifyTab" 
                                                runat="server" 
                                                Title="Status/Notification" 
                                                Icon="ChartOrganisation"
                                                BodyStyle="padding:5px;">
                                                <Body>
                                                    <ext:FormLayout ID="FormLayout1" runat="server">
                                                        <%--<ext:Anchor>
                                                            <ext:TextField 
                                                                ID="BadgermailTypeID"
                                                                runat="server" 
                                                                FieldLabel="Badgermail ID"
                                                                Width="250"
                                                                Disabled="true"
                                                                />
                                                        </ext:Anchor>--%>
                                                        <ext:Anchor>
                                                            <ext:ComboBox ID="cbActive" runat="server" FieldLabel="Active">
                                                                <Items>
                                                                    <ext:ListItem Text="Yes" Value="Y" />
                                                                    <ext:ListItem Text="No" Value="N" />
                                                                </Items>
                                                            </ext:ComboBox>
                                                        </ext:Anchor>                                                              
                                                        <ext:Anchor>
                                                            <ext:ComboBox ID="cbInitNotify" runat="server" FieldLabel="Initial Notify">
                                                                <Items>
                                                                    <ext:ListItem Text="Yes" Value="Y" />
                                                                    <ext:ListItem Text="No" Value="N" />
                                                                </Items>
                                                            </ext:ComboBox>
                                                        </ext:Anchor>                             
                                                        <ext:Anchor>
                                                            <ext:ComboBox ID="cbBeforeTargetDate" runat="server" FieldLabel="Before Target Date">
                                                                <Items>
                                                                    <ext:ListItem Text="1 Day" Value="1" />
                                                                    <ext:ListItem Text="2 Days" Value="2" />
                                                                    <ext:ListItem Text="7 Days" Value="7" />  
                                                                    <ext:ListItem Text="14 Days" Value="14" />
                                                                    <ext:ListItem Text="30 Days" Value="30" />
                                                                    <ext:ListItem Text="60 Days" Value="60" />                                                                                                                                                                               
                                                                    <ext:ListItem Text="90 Days" Value="90" />                                    
                                                                </Items>
                                                            </ext:ComboBox>
                                                        </ext:Anchor> 
                                                        <ext:Anchor>
                                                            <ext:ComboBox ID="cbNotifyFrequency" runat="server" FieldLabel="Notify Frequency">
                                                                <Items>
                                                                    <ext:ListItem Text="1 Day" Value="1" />
                                                                    <ext:ListItem Text="2 Days" Value="2" />
                                                                    <ext:ListItem Text="7 Days" Value="7" />  
                                                                    <ext:ListItem Text="14 Days" Value="14" />
                                                                    <ext:ListItem Text="30 Days" Value="30" />
                                                                    <ext:ListItem Text="60 Days" Value="60" />                                                                                                                                                                               
                                                                    <ext:ListItem Text="90 Days" Value="90" />                                    
                                                                </Items>
                                                            </ext:ComboBox>
                                                        </ext:Anchor>                                                            
    
                                                        
                                                        <ext:Anchor>
                                                            <ext:TextField 
                                                                ID="LastName"
                                                                runat="server" 
                                                                FieldLabel="Last Name"
                                                                Width="250"
                                                                />
                                                        </ext:Anchor>
                                                        
                                                        <ext:Anchor>
                                                            <ext:TextField 
                                                                ID="Title"
                                                                runat="server" 
                                                                FieldLabel="Title"
                                                                Width="250"
                                                                />
                                                        </ext:Anchor>
                                                        
                                                        <ext:Anchor>
                                                            <ext:ComboBox 
                                                                ID="ReportsTo"
                                                                runat="server" 
                                                                StoreID="Facility_Store"
                                                                FieldLabel="Reports to" 
                                                                AllowBlank="true"
                                                                DisplayField="LastName"
                                                                ValueField="EmployeeID"
                                                                TypeAhead="true" 
                                                                Mode="Local"
                                                                ForceSelection="true"
                                                                TriggerAction="All"
                                                                EmptyText="Select an employee..."
                                                                Width="250"
                                                                />
                                                        </ext:Anchor>
                                                        
                                                        <ext:Anchor>
                                                            <ext:DateField 
                                                                ID="HireDate" 
                                                                runat="server" 
                                                                Width="250" 
                                                                FieldLabel="Hire date"
                                                                Format="yyyy-m-d"
                                                                />
                                                        </ext:Anchor>
                                                        
                                                        <ext:Anchor>
                                                            <ext:TextField 
                                                                runat="server" 
                                                                ID="Extension"
                                                                FieldLabel="Extension"
                                                                Width="250"
                                                                />
                                                        </ext:Anchor>
                                                    </ext:FormLayout>
                                                </Body>
                                            </ext:Tab>
                                            <ext:Tab 
                                                ID="EmailSchedulerTab" 
                                                runat="server" 
                                                Title="Email/TaskScheduler" 
                                                Icon="User"
                                                BodyStyle="padding:5px;">
                                                <Body>
                                                    <ext:FormLayout ID="FormLayout2" runat="server">
                                                        <ext:Anchor>
                                                            <ext:TextField 
                                                                ID="BadgermailTypeID2"
                                                                runat="server" 
                                                                FieldLabel="Employee ID"
                                                                Width="250"
                                                                Disabled="true"
                                                                />
                                                        </ext:Anchor>
                                                        
                                                        <ext:Anchor>
                                                            <ext:TextField 
                                                                ID="Address"
                                                                runat="server" 
                                                                FieldLabel="Address"
                                                                Width="250"
                                                                />
                                                        </ext:Anchor>
                                                        
                                                        <ext:Anchor>
                                                            <ext:TextField 
                                                                ID="City" 
                                                                runat="server" 
                                                                FieldLabel="City"
                                                                Width="250"
                                                                />
                                                        </ext:Anchor>
                                                        
                                                        <ext:Anchor>
                                                            <ext:TextField 
                                                                ID="PostCode"
                                                                runat="server" 
                                                                FieldLabel="Post Code"
                                                                Width="250"
                                                                />
                                                        </ext:Anchor>
                                                        
                                                        <ext:Anchor>
                                                            <ext:TextField 
                                                                ID="HomePhone" 
                                                                runat="server" 
                                                                FieldLabel="Home Phone"
                                                                Width="250"
                                                                />
                                                        </ext:Anchor>
                                                        
                                                        <ext:Anchor>
                                                            <ext:TextField 
                                                                ID="TitleCourt" 
                                                                runat="server" 
                                                                FieldLabel="Title Of Courtesy"
                                                                Width="250"
                                                                />
                                                        </ext:Anchor>
                                                        
                                                        <ext:Anchor>
                                                            <ext:DateField 
                                                                ID="BirthDate" 
                                                                runat="server" 
                                                                Width="233" 
                                                                FieldLabel="Birth date"
                                                                Format="yyyy-m-d"
                                                                />
                                                        </ext:Anchor>
                                                            
                                                        <ext:Anchor>
                                                            <ext:TextField 
                                                                ID="Region" 
                                                                runat="server" 
                                                                FieldLabel="Region"
                                                                Width="250"
                                                                />
                                                        </ext:Anchor>
                                                        
                                                        <ext:Anchor>
                                                            <ext:TextField 
                                                                ID="Country" 
                                                                runat="server" 
                                                                FieldLabel="Country"
                                                                Width="250"
                                                                />
                                                        </ext:Anchor>
                                                        
                                                        <ext:Anchor>
                                                            <ext:TextArea 
                                                                ID="Note" 
                                                                runat="server" 
                                                                FieldLabel="Note"
                                                                Height="50" 
                                                                Width="250"
                                                                />
                                                        </ext:Anchor>
                                                    </ext:FormLayout>                            
                                                </Body>
                                            </ext:Tab>
                                            <ext:Tab 
                                                ID="DisplayFieldsTab" 
                                                runat="server" 
                                                Title="Display Fields/DB" 
                                                Icon="Database"
                                                BodyStyle="padding:5px;">
                                                <Body>
                                                    <ext:FormLayout ID="FormLayout3" runat="server">
                                                        <ext:Anchor>
                                                            <ext:CheckboxGroup ID="cbgDisplayFields" runat="server" HideLabel="true" ColumnsNumber="2">
                                                                <Items>
                                                                    <ext:Checkbox ID="Checkbox1" runat="server" BoxLabel="Checkbox 1" Hidden="true" />
                                                                </Items>
                                                            </ext:CheckboxGroup>
                                                        </ext:Anchor>
                                                    </ext:FormLayout>
                                                </Body>    
                                            </ext:Tab>                    
                                        </Tabs>                
                                    </ext:TabPanel>
                                </ext:FitLayout>
                            </Body>
                            <Buttons>
                                <ext:Button ID="SaveButton" runat="server" Text="Save" Icon="Disk">
                                   <Listeners>
                                        <Click Handler="saveEmployee();" />
                                    </Listeners>
                                </ext:Button>
                                <ext:Button ID="CancelButton" runat="server" Text="Cancel" Icon="Cancel">
                                    <Listeners>
                                        <Click Handler="#{EmployeeDetailsWindow}.hide(null);" />
                                    </Listeners>
                                </ext:Button>
                            </Buttons>
                        </ext:Window>
  10. #20
    Hi,

    Not sure this will help but try to set DeferredRender to "False" for TabPanel.

    Example
    <ext:TabPanel ... DeferredRender="false">
Page 2 of 5 FirstFirst 1234 ... LastLast

Similar Threads

  1. [CLOSED] Checkboxgroup not retaining checkbox items
    By Edward in forum 1.x Legacy Premium Help
    Replies: 13
    Last Post: Apr 21, 2015, 12:23 PM
  2. Replies: 7
    Last Post: Feb 13, 2012, 2:25 PM
  3. Replies: 2
    Last Post: Jan 12, 2012, 1:33 PM
  4. Runtime Checkbox value update issue.
    By ajviradia in forum 1.x Help
    Replies: 1
    Last Post: Apr 08, 2011, 5:23 PM
  5. [CLOSED] CheckBoxGroup DataIndex for each child checkbox
    By webclouder in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: May 11, 2010, 4:22 PM

Posting Permissions