1 Reply Latest reply on Oct 10, 2010 9:41 PM by Flex harUI

    alert stops event(?)/binding(?) propogation - unless nonmodal?

    wwesbie

      I'm new to Flex - so I'm not sure if this behavior is due to focus or events or what...

      I currently must use SDK 3.5.

       

      In my example - I have 3 controls/components - 2 Grids and 1 TextInput.

      They are bound to globals / so that they stay in sync with each other.

      On the TextInput - I have a RegExpValidator to check for wellformedness

      Within the handler for the RegExpValidator - I have an additional check for some additional criteria.

      If this additional criteria is met - I need to display a warning message to the user...

       

      What I have noticed is the following...

      ...If the alert is NONMODAL - then all the grids and data stay in sync (as desired).

      ...If the alert is modal - then the grid that clicks selected item is updated - but the change doesn't propogate to the other controls/components.

       

      As I am new to the platform - I don't exactly know how to word this to  google it...  So my searches thus far have yielded great information for everything but my problem

       

      Do I need to call something specific to propogate the changes if its a modal?  I'm hoping that this is the case...

      I probably could do this by specifically updating each component from the code where the alert is - but that seems like a really bad idea..

       

      To illustrate - I threw together this simplification of what I'm trying...

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="600"
                      creationComplete="init()">
         
          <mx:Script>
              <![CDATA[
                  import mx.collections.ArrayCollection;
                  import mx.controls.Alert;
                  import mx.events.ValidationResultEvent;
                  import mx.validators.Validator;
                 
                  [Bindable]
                  public var ListA:ArrayCollection = new ArrayCollection();
                  [Bindable]
                  public var curIndex:int;
                  public function setCurIndex():void {curIndex = Grid1.selectedIndex;}
                  public function setCurIndexB():void {curIndex = Grid2.selectedIndex;}
                  public function Checkit(e:ValidationResultEvent):void {
                      if (e.type == ValidationResultEvent.INVALID) {
                          e.stopPropagation();
                          Alert.show("Doesn't start with 'www.'   Enter www.something to continue...", "Error", Alert.OK);
                          Grid1.selectedIndex = curIndex;
                          Grid2.selectedIndex = curIndex;
                      }
                      else {
                          if ( txt1.text == "www.zzzzz.com")
                              Alert.show("Propogation should continue between grids - but doesn't....  Type www.somethingelse in the text to get going again....", "Warning", Alert.OK);
                          if (txt1.text == "www.zzzzz_nonmodal.com")
                              Alert.show("Propogation continues between grids - but as nonmodal  ??!?", "Warning", Alert.OK|Alert.NONMODAL);
                          if (txt1.text == "www.zzzzz_Later.com")
                              callLater(function():void {
                                  Alert.show("Propogation should continue between grids - but doesn't.... ...this from a callLater...", "Warning", Alert.OK);});
                      }
                  }
                  private function init():void {
                      ListA.addItem("www.google.com");
                      ListA.addItem("www.bing.com");
                      ListA.addItem("www.yahoo.com");
                      ListA.addItem("www.zzzzz.com");    //this should throw a warning and propogate - but doesn't
                      ListA.addItem("www.zzzzz_Later.com");    //this should throw a warning and propogate - but doesn't
                      ListA.addItem("www.zzzzz_nonmodal.com");    //this should throw a warning and propogate - and does but as NonModal
                      ListA.addItem("qwerty"); //this should fail validation - it does
                  }
              ]]>
          </mx:Script>
         
         
          <mx:DataGrid x="10" y="48" id="Grid1"  editable="false" draggableColumns="false"
                       dataProvider="{ListA}" rowCount="{ListA.length}" selectedIndex="{curIndex}"
                       itemClick="setCurIndex()" >
              <mx:columns>
                  <mx:DataGridColumn headerText="Column 1" dataField="col1"/>
                  <mx:DataGridColumn headerText="Column 2" dataField="col2"/>
              </mx:columns>
          </mx:DataGrid>
         
          <mx:DataGrid x="10" y="255" id="Grid2"  editable="false" draggableColumns="false"
                       dataProvider="{ListA}" rowCount="{ListA.length}" selectedIndex="{curIndex}"
                       itemClick="setCurIndexB()" >
              <mx:columns>
                  <mx:DataGridColumn headerText="Column 1" dataField="col1"/>
                  <mx:DataGridColumn headerText="Column 2" dataField="col2"/>
              </mx:columns>
          </mx:DataGrid>
         
          <mx:TextInput x="10" y="216" id="txt1" text="{ListA.getItemAt(curIndex)}"/>
         
          <mx:RegExpValidator id="RegExCheck"
                              source="{txt1}" property="text"
                              flags="g" expression="^www\..*"
                              valid="Checkit(event)"
                              invalid="Checkit(event)"
                              trigger="{txt1}"
                              triggerEvent="focusOut"
                              />
          <mx:Label x="10" y="10" text="1) Select something in a grid - 2) Click in the TextInput - 3) Click in a Grid - 4)Repeat" width="507" height="30"/>
         
      </mx:Application>

       

      Thanks in advance.