saving dynamically-created controls' values

  1. #1

    saving dynamically-created controls' values

    I have the following window in which I'm creating controls from the code-behind and adding them to the FieldSet:

            <ext:Window ID="winMapping" runat="server" AutoHeight="true" Closable="false" Width="400" AutoShow="false" Modal="true" Hidden="true" Layout="FitLayout" Icon="TableRelationship" OnLoad="winMapping_OnLoad" Maximizable="true">
                <Items>
                    <ext:FormPanel ID="fpMapping" runat="server" AutoHeight="true" Padding="5" MonitorValid="true" MonitorPoll="500">
                        <Defaults>
                            <ext:Parameter Name="MsgTarget" Value="side" />
                        </Defaults>
                        <Items>
                            <ext:Hidden ID="hidSCFElementId" runat="server" />
                            <ext:Hidden ID="hidSourceSystemMappingId" runat="server" />
                            <ext:Hidden ID="hidRequestType" runat="server" />
    
                            <ext:FieldSet ID="fsSegmentFieldPairs" runat="server" Title="Segment/Field Pairs" Layout="FormLayout" Collapsible="false">
                                <Items>
                                    <ext:Hidden ID="hidFieldPairId_1" runat="server" />
                                    <ext:TextField ID="txtSegment_1" runat="server" FieldLabel="Segment/Table 1" Width="200" AllowBlank="false" />
                                    <ext:TextField ID="txtFieldName_1" runat="server" FieldLabel="Field Name 1" Width="200" AllowBlank="false" />
                                </Items>
                                <BottomBar>
                                    <ext:Toolbar runat="server">
                                        <Items>
                                            <ext:Button ID="btnAddPair" runat="server" Text="Add Pair" Icon="Add" StandOut="true">
                                                <DirectEvents>
                                                    <Click OnEvent="btnAddPair_Click" />
                                                </DirectEvents>
                                            </ext:Button>
                                        </Items>
                                    </ext:Toolbar>
                                </BottomBar>
                            </ext:FieldSet>
                        </Items>
                        <Buttons>
                            <ext:Button ID="btnSaveMapping" runat="server" Text="Save" Icon="Disk" AutoPostBack="false">
                                <Listeners>
                                    <Click Handler="saveMappings(#{fsSegmentFieldPairs});" />
                                </Listeners>
                            </ext:Button>
                        </Buttons>
                    </ext:FormPanel>
                </Items>
            </ext:Window>
    Here's a snippet of code depicting how I add dynamic controls to the FieldSet:

                        hid = new Hidden();
                        hid.ID = String.Format("hidFieldPairId_{0}", intIndex + 1);
                        hid.AddTo(this.fsSegmentFieldPairs);
    
                        txt = new TextField();
                        txt.ID = String.Format("txtSegment_{0}", intIndex + 1);
                        txt.FieldLabel = String.Format("Segment/Table {0}", intIndex + 1);
                        txt.Width = 200;
                        txt.AllowBlank = false;
                        txt.AddTo(this.fsSegmentFieldPairs);
    
                        txt = new TextField();
                        txt.ID = String.Format("txtFieldName_{0}", intIndex + 1);
                        txt.FieldLabel = String.Format("Field Name {0}", intIndex + 1);
                        txt.Width = 200;
                        txt.AllowBlank = false;
                        txt.AddTo(this.fsSegmentFieldPairs);
    When I click the Window's "Save" button, the function shown below is invoked on the client. The code recognizes that I have added new controls (fsSegmentFieldPairs.items.length has the correct number). None of the dynamically-created controls have a value attribute on them. What am I doing wrong? How do I retrieve the value from these newly created controls?

            var saveMappings = function (fsSegmentFieldPairs) {
                var ctrl = null;
                var intSourceSystemMappingFieldId = null;
                var strSegment, strField, strListItem;
                var arrCtrl = [];
    
                for (var intIndex = 0; intIndex < fsSegmentFieldPairs.items.length; intIndex++) {
                    ctrl = fsSegmentFieldPairs.items.items[intIndex];
    
                    if (ctrl.id.indexOf("hidFieldPairId_") > -1) {
                        intSourceSystemMappingFieldId = ctrl.value;
    
                        // if there is no value, then this pair needs to be added to the DB
                        if (ctrl.value !== undefined && ctrl.value !== null) {
                            intSourceSystemMappingFieldId = parseInt(ctrl.value);
                        }
                    }
                    else if (ctrl.id.indexOf("txtSegment_") > -1) {
                        strSegment = ctrl.value;
                    }
                    else if (ctrl.id.indexOf("txtFieldName_") > -1) {
                        strField = ctrl.value;
                        strListItem = intSourceSystemMappingFieldId + "|" + strSegment + "|" + strField;
                        arrCtrl.push(strListItem);
                    }
                }
    
                for (var intIndex = 0; intIndex < arrCtrl.length; intIndex++) {
                    alert(arrCtrl[intIndex]);
                }
            };
  2. #2
    Hi,

    Please use the getValue method to get a field value.
    http://docs.sencha.com/ext-js/3-4/#!...ethod-getValue

Similar Threads

  1. [CLOSED] How to clean up dynamically created controls?
    By jchau in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Aug 23, 2011, 9:51 AM
  2. [CLOSED] Unable to access dynamically created controls
    By rnachman in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Apr 07, 2011, 5:49 AM
  3. Replies: 2
    Last Post: Jan 03, 2011, 5:34 PM
  4. Dynamically created controls cookbooks
    By arodier in forum 1.x Help
    Replies: 15
    Last Post: May 07, 2010, 7:12 PM
  5. [CLOSED] Unable to render controls within dynamically created TabPanel
    By Hari_CSC in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Mar 29, 2010, 10:04 AM

Posting Permissions