10 Replies Latest reply on Aug 24, 2010 5:32 AM by betheflexcoder

    Flex. How to get textinput text values in dynamic..?

    Ling's Level 1

      Hi all.,

       

              I have using dynamic form to get  the textinput text values.

      <fx:Script>

       

              <![CDATA[

      public function init():void

      {

                frmItem1 = new FormItem();
                  frmItem1.direction = "horizontal";
                  frmItem1.label = "Customer Name";
                  txtinput1 = new TextInput();
                  txtinput1.id="txt_custname";
                  txtinput1.width=170;
                  frmItem1.addElement(txtinput1);
                  userInfoForm.addElement(frmItem1);

      }

       

        public function search_click():void

         {

           user.text="custname"+.text;


          }
              ]]>
             
          </fx:Script>
          <fx:form id="userInfoForm"/>

      <fx:Label id="user"/>
          <s:Button id="btn_search" label="Search" click="search_click();"/>

       

       

      error displayed.  how to get textinput id and text

      any one help this problem...

       

       

      Ling's

        • 1. Re: Flex. How to get textinput text values in dynamic..?
          Prestine Level 1

          use,

           

          str = txtinput1.text

           

          which will return the text contains in the TextInput.

           

           

          Regards,

          • 2. Re: Flex. How to get textinput text values in dynamic..?
            Ling's Level 1

            Thank u....

             

            but i want to add 2 r more textinput using loop  through arraycollection

            txtinput1.id="customer_id"

            txtinput1.id="customer_name"

            txtinput1.id="customer_address"

            txtinput1.id="customer_state"

             

            to get

            str1=customer_id.text;

            str1=customer_name.text

            str1=customer_address.text;

            str1=customer_state.text

             

            ist poosible to get the id in dynamic..?

             

            regards.,

            Ling's

            • 3. Re: Flex. How to get textinput text values in dynamic..?
              betheflexcoder Level 2

              How about using your custom textinput, so that you can create dynamic ids for each of its instances.

              • 4. Re: Flex. How to get textinput text values in dynamic..?
                Vackar Level 2

                You could try userInfoForm.getChildren();

                 

                This returns the list of FormItem Objects.

                 

                Then for each one call getChildren().getItem(0) to get the text box.

                 

                Note: I haven't compiled this - syntax may not be exact.

                 

                Thanks,

                Vackar

                • 5. Re: Flex. How to get textinput text values in dynamic..?
                  Ling's Level 1

                  any sample coding to solve this problem.....

                   

                   

                  regards.,

                  • 6. Re: Flex. How to get textinput text values in dynamic..?
                    Balakrishnan V Level 3

                    I am not very sure what you are trying to achieve; In any case, with my understanding here are a couple of my suggestions

                     

                    You can have the TextInput components as an ArrayCollection.

                     

                    var textInputArrayCollection:ArrayCollection=new ArrayCollection()

                     

                    var textInput1:TextInput=new TextInput();

                    //either declare your component in mxml and set textInput1=mxmlTextInputComponent

                    //and repeatedly do texInputArrayCollection.addItem(textInput1)

                     

                    textInput1.id="abc"

                    .

                    .

                    //set other properties - here no mxml declaration

                    textInputArrayCollection.addItem(textInput1)

                     

                    You can use TextInput(textInputArrayCollection.getItemAt(i)) to access any properties.

                     

                    OR, you can map the textinputs through an object

                     

                    var obj:Object=new Object();

                    obj["textInput1"]=textInput1

                    obj["textInput2"]=textInput2 .....

                     

                    Hope this helps, If you could e3laborate what u want to do, I could help better !

                     

                    balakrishnan v

                    • 7. Re: Flex. How to get textinput text values in dynamic..?
                      Ling's Level 1

                      thank u...

                       

                      Form is created dynamic., with  4 formitem and   textinput

                      <fx:Script>
                              <![CDATA[

                       

                      //dataist  arraycollectiion data .

                       

                                     [Bindable]
                                  public var dataist:ArrayCollection = new ArrayCollection( [
                                      { spkName:customer Name', dataName:'customer_name'},
                                      { spkName:customer address', dataName:'customer_add'},

                                     { spkName:customer state', dataName:'customer_state'},

                                     { spkName:customer city', dataName:'customer_city'}

                      ])

                       

                      public var frmitem:FormItem;

                      public var txtInput:TextInput;

                       

                      public function init():void

                      {   
                         // loop is executed 4 times 
                        for(var i:int = 0; i < dataist.length(); i++)

                      {

                          var formlabel:String= lst[i].spkName;

                         var textvalues:String= lst[i].dataName;


                              frmItem = new FormItem();
                              frmItem.direction = "horizontal";
                              frmItem.label = formlabel;

                       

                              txtInput = new TextInput();
                              txtInput.id= textvalues;
                              frmItem.addChild(txtInput);

                      }

                      userInfoForm.addChild(frmItem);

                      }

                       

                      public function buttonclick():void

                      {

                      // Error displayed

                      var customername:String=txtInput.text;   OR    var customername:String="customer_name"+.text;

                      var customeradd:String=txtInput.text;

                      var customerstate:String=txtInput.text;

                      var customercity:String=txtInput.text;

                       

                      // How to get all textinput text ...

                      }

                       

                      ]]>
                          </fx:Script>

                          <mx:VBox >
                              <mx:HBox>
                                   <mx:Form  id="userInfoForm" >
                                   </mx:Form>
                               </mx:HBox>
                               
                          <mx:Button id="test"  label="Click" click="buttonclick()" />

                            </mx:VBox>

                       

                       

                      // How to get all textinput text ...
                      regards

                      Ling's

                       


                      • 8. Re: Flex. How to get textinput text values in dynamic..?
                        Balakrishnan V Level 3

                        <fx:Script>
                                <![CDATA[

                        //dataist  arraycollectiion data .

                                       [Bindable] public var dataist:ArrayCollection = new ArrayCollection( [
                                        { spkName:customer Name', dataName:'customer_name'},
                                        { spkName:customer address', dataName:'customer_add'},

                                        { spkName:customer state', dataName:'customer_state'},

                                        { spkName:customer city', dataName:'customer_city'}])

                         

                        public var frmitem:FormItem;

                        public var txtInput:TextInput;

                         

                        public function init():void

                        {   
                           // loop is executed 4 times 
                          for(var i:int = 0; i < dataist.length(); i++)

                          {

                            var formlabel:String= lst[i].spkName;

                            var textvalues:String= lst[i].dataName;


                                frmItem = new FormItem();
                                frmItem.direction = "horizontal";
                                frmItem.label = formlabel;

                         

                                txtInput = new TextInput();
                                txtInput.id= textvalues;
                                frmItem.addChild(txtInput);

                                userInfoForm.addChild(frmItem);

                          }

                        }

                         

                        public function buttonclick():void

                        {

                        // Error displayed

                        var customername:String=txtInput.text;   OR    var customername:String="customer_name"+.text;

                        var customeradd:String=txtInput.text;

                        var customerstate:String=txtInput.text;

                        var customercity:String=txtInput.text;

                        // How to get all textinput text ...

                         

                        var customername:String=userInfoform.getChildAt(0).text;

                        OR var customername:String=TextInput(userInfoForm.getChildAt(0)).text

                        }

                         

                        Hope this helps,

                         

                        Balakrishnan V

                        • 9. Re: Flex. How to get textinput text values in dynamic..?
                          Ling's Level 1

                          var customername:String=TextInput(userInfoForm.getChildAt(0)).text

                           

                           

                          Error display

                          Type Coercion failed: cannot convert mx.containers::FormItem@3a7040a1 to mx.controls.TextInput.

                           

                          userInfoForm form is mx.container

                          TextInput is mx.control.

                           

                          how to conver this...

                           

                           


                          • 10. Re: Flex. How to get textinput text values in dynamic..?
                            betheflexcoder Level 2

                            You have get the child of the formitem and then type cast it ti textinput.

                             

                            May be like,

                             

                            var customerFormItem:FormItem =FormItem(userInfoForm.getChildAt(0));

                             

                            var customerName:String = TextInput(customerFormItem.getCHildAt(0)).text;