3 Replies Latest reply on Nov 20, 2006 9:40 AM by ntsiii

    binding to a repeater item

      Does anyone know of how to bind a model to form items that were dynamically generated using the repeater tag. It's easy enough to refer to the repeater items through their position in an array (i.e. myTextInputArray[x]). However, bindings do not bind to elements that use square brackets for identifing a source. The alternative ways of referencing items in an array - getItemAt(i) - does not seem to work on a repeated item. Any idea?

      This is roughly what I am trying to do. The dataProvider for the repeater (deductionsItems) is set with actionscript. On submitting the form, there is no problem with getting the value of the repeated items using deductionInputArray[2].text, for instance. The problem is that I cant get the model to bind to the items automatically.
      <mx:Model id="payrollItemRecord">
      <Deduction_1>{deductionInputArray[0].text}</Deduction_1>// square brackets throw a warning in flex and does not bind

      <mx:Repeater id="deductionsItems">
      <mx:TextInput id="deductionInputArray" height="20" width="100" fontWeight="normal"/>
        • 1. Re: binding to a repeater item
          ntsiii Level 3
          How is "deductionInputArray" being populated? Can you wrap it in an ArrayCollection?
          • 2. Re: binding to a repeater item
            fred2180 Level 1
            deductionInputArray is being populated as the mx:Repeater executes for each item in its dataProvider - in this case, lets say I have 4 items in that dataProvider which the mx:Repeater will then create 4 textInputs. deductionInputArray will then have a length of 4 and each item will be a reference to the corresponding TextInput. I can access the value of, let's say the 3rd TextInput, by the following: deductionInputArray [2].text.

            However, the problem I'm having is that Flex doesn't allow you to bind to array items with square brackets. I'm not sure if there is a way to convert that array(deductionInputArray) that gets created by the repeater into an ArrayCollection so I can use getItemAt(x) methods in the binding. Otherwise, I think I will have to just loop through the deductionInputArray array on submit and manually update the model - which elliminate the need for any bindings.

            Thoughts? It looks like this might be a deficiency of Flex bindings and repeated text inputs unless I am missing something - which is certainly possible. Any suggestions would be appreciated!
            • 3. Re: binding to a repeater item
              ntsiii Level 3
              The problem is that you can't bind to a plain array.

              If you are doing this to build a request object to send to a data service, than I'd say forget the binding and build the request object programmatically. Binding is supposed to make life simpler. If you have to jump through hoops to make it work, you've lost the benefit.