10 Replies Latest reply on Jun 17, 2008 1:28 PM by VarioPegged

    Accordion with a Repeater and TextInput

    flatpickinJohn Level 1
      I'm using an XMLList as a dataprovider to populate forms. The number of forms generated are based on the number of children in the XML list. This works fine, the problem is when I try to edit the form. What is the proper code for the the change property of the TextInputs?

      Thanks!

      John
        • 1. Re: Accordion with a Repeater and TextInput
          flatpickinJohn Level 1
          I'm thinking the answers lies with the getRepeaterItem() but I can't get it to work
          • 2. Re: Accordion with a Repeater and TextInput
            VarioPegged Level 2
            Edit the form at runtime or in the coding environment? TextInput has a "change" event that you can listen for. If you can provide some code it'd be easier to help.

            TS
            • 3. Re: Accordion with a Repeater and TextInput
              flatpickinJohn Level 1
              I fill the form from an XMLList then I want to edit and bind the edit back to the xml. binding the edit back is where i'm having trouble. It is something with the change event...i think. I attached the code with just one textinput to keep it easier to read.

              thanks

              John

              <!--Create an accordion for Contacts-->
              <mx:Accordion width="360" height="610" x="837" y="10" backgroundColor="#FFD897" cornerRadius="5" borderThickness="3" id="contactAccordion" creationPolicy="auto">
              <!--Repeat the child content-->
              <mx:Repeater id="repeat" dataProvider="{populateContactXML}" >

              <mx:Form xmlns:mx=" http://www.adobe.com/2006/mxml" width="360" height="585" borderStyle="none" backgroundColor="#E1E1E1" cornerRadius="5" borderThickness="3" >
              <mx:FormHeading label="Contact Information"/>
              <mx:FormItem id="contactTypeItem" label="Contact Type" width="290" x="790" y="10">
              <mx:TextInput id="contactType" width="183" borderStyle="solid" cornerRadius="5" text="{repeat.currentItem.@Contact_Type}" enabled="true">
              </mx:TextInput>
              </mx:FormItem>



              <mx:FormItem id="address1Item" label="Address 1" width="290">
              <mx:TextInput id="address1" change="{event.currentTarget.getRepeaterItem()}" width="183" borderStyle="solid" cornerRadius="5" text="{repeat.currentItem.@Address_1}" >
              </mx:TextInput>
              </mx:FormItem>

              </mx:Repeater>
              </mx:Accordion>
              • 4. Re: Accordion with a Repeater and TextInput
                flatpickinJohn Level 1
                I think i'm getting close with:

                change="{populateContactXML = event.currentTarget.getRepeaterItem()}"

                I get this error:

                TypeError: Error #1034: Type Coercion failed: cannot convert XML@7a2d821 element <CON Email="" Address_1="Test" Address_2="" Address_3="" Address_4="" Address_5="" MP_CountryCode_Id="" FirstName="" LastName="" Business_Phone="" Cell_Phone="" City="" State="" Zip="" County="" Upload_Origin="" Update_Origin="" Delete_Origin="" Status="" Contact_Type="" Country="" Fax="" Upload_Date="" Update_Date="" MP_State_Province_Id="0" Version="0" Plus4="0" SE_Party_Contact_Id="0006021D-AA77-FF59-24C7-FA5F6D552000" SE_Party_Id="0006021D-AA77-FF59-24C7-FA5F6D552000" SE_Party_Record_ID="0006021D-AA77-FF59-24C7-FA5F6D552000" SE_Party_Contacts_Record_ID="0006021D-AA77-FF59-24C7-FA5F6D552000"/> to XMLList.
                at CommercePartyDataEntry/__address1_change()[C:\Users\John\Documents\Flex Builder 3\CommerceParty\src\CommercePartyDataEntry.mxml:566]
                at flash.events::EventDispatcher/dispatchEventFunction()
                at flash.events::EventDispatcher/dispatchEvent()
                at mx.core::UIComponent/dispatchEvent()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\co re\UIComponent.as:9051]
                at mx.controls::TextInput/textField_changeHandler()[E:\dev\3.0.x\frameworks\projects\framewo rk\src\mx\controls\TextInput.as:2202]
                • 5. Re: Accordion with a Repeater and TextInput
                  VarioPegged Level 2
                  You could try...
                  (address1 example):

                  change="onChange(event, event.currentTarget.getRepeaterItem(), 'Address_1')"

                  then your onChange() handler:

                  public function onChange(event:Event, obj:Object, str:String):void
                  {
                  var count:uint = 0;
                  for each (var item:XML in populateContactXML) {
                  if (item == XML(obj)) {
                  item["@" + str] = event.currentTarget.text;
                  populateContactXML[count] = item;
                  break;
                  }
                  count++;
                  }
                  }
                  Dunno if this is what you're looking to do though.

                  So you don't have to pass "Address_1", you could give the TextInput an id of that element it refers to.

                  TS
                  • 6. Re: Accordion with a Repeater and TextInput
                    VarioPegged Level 2
                    A simpler approach ... pass the repeaterIndex:

                    (address1 example):

                    change="onChange(event, event.currentTarget.repeaterIndex, 'Address_1')"

                    then your onChange() handler:

                    public function onChange(event:Event, idx:int, str:String):void
                    {
                    populateContactXML[idx]["@" + str] = event.currentTarget.text;
                    }

                    TS
                    • 7. Re: Accordion with a Repeater and TextInput
                      flatpickinJohn Level 1
                      Thanks TS...works like a charm!
                      • 8. Re: Accordion with a Repeater and TextInput
                        flatpickinJohn Level 1
                        I did notice right now it only works on the first contact form thats loaded. if you select any other form and edit it does not edit and the index is correct. But still a major breakthrough
                        • 9. Re: Accordion with a Repeater and TextInput
                          flatpickinJohn Level 1
                          My mistake. I had to scroll down to see the changes

                          Thanks TS!
                          • 10. Re: Accordion with a Repeater and TextInput
                            VarioPegged Level 2
                            Glad that worked for you.

                            TS