Skip navigation
cougheno
Currently Being Moderated

Can you use two way data binding with view states conditionals?

Apr 22, 2013 10:17 AM

I'd like to use one component and have what data is shown and where the data is saved vary based on the currentState of the Application/Skin/etc.  It seems to work fine for displaying different data but when I introduce two way binding the set from the ui component back to the variable is never called.  I have a minimum case example showing what I'm trying to get working below.

 

Thanks for any insight.

 

<?xml version="1.0" encoding="utf-8"?>

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

                                 xmlns:s="library://ns.adobe.com/flex/spark">

      <fx:Declarations>

          <!-- Place non-visual elements (e.g., services, value objects) here -->

          <fx:String id="myVar1">1</fx:String>

          <fx:String id="myVar2">2</fx:String>

        </fx:Declarations>

 

   <s:states>

      <s:State name="state1"/>

      <s:State name="state2"/>

   </s:states>

 

   <s:Form>

      <s:FormItem>

         <s:HGroup>

            <s:Button label="State 1" click="{currentState='state1'}"/>

            <s:Button label="State 2" click="{currentState='state2'}"/>

         </s:HGroup>

      </s:FormItem>

 

      <!-- Works As Expected but lots of duplicate code -->

      <s:FormItem label="MyVar1" includeIn="state1">

         <s:TextInput text="@{myVar1}"/>

      </s:FormItem>

      <s:FormItem label="MyVar2" includeIn="state2">

         <s:TextInput text="@{myVar2}"/>

      </s:FormItem>

 

 

      <!-- Display updates as expected, Set to myVar1 or MyVar2 is never called -->

      <s:FormItem label="State Based">

         <s:TextInput

            text.state1="@{myVar1}"

            text.state2="@{myVar2}"

         />

      </s:FormItem>

   </s:Form>

</s:Application>

 

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points