0 Replies Latest reply on Aug 10, 2011 6:18 PM by Daryl_69

    Resetting spark list components and errorString not working as expected





      I would like to reset the list components  (DropDownList, List, ComboBox) on a form. Normally with mx components I set the selectedIndex to 0 (or -1) and then set errorString on the component to "" this resets the list and hides the error message generated by a validator on the component.


      I'm finding that with spark lists I'm having to delay setting the errorString to "" after setting the selected index to 0.


      Below is a form which demonstrates the behaviour.

      Make a selection in each list then click the clear button. The spark components show an error - not what I expect.

      Then repeat the above but with the Call later check box selected - now the form works as expected.

      1. Why do I have to delay clearing the errorString on spark lists?
      2. Am I doing something wrong?



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

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


         xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"



      <s:VerticalLayout horizontalAlign="center" verticalAlign="middle"/>





      import mx.core.UIComponent;

      import mx.events.FlexEvent;

      import mx.events.ValidationResultEvent;

      import mx.validators.Validator;


      private function okBtn_clickHandler(event:MouseEvent):void


      if (validatePage())

      resultLbl.text = "Good";


      resultLbl.text = "Bad";



      public function validatePage():Boolean


      return Validator.validateAll(validatorList).length == 0;



      public function clearValidationErrors():void


      for each (var validator:Validator in validatorList)


      validator.source.errorString = "";


      resultLbl.text = "";



      private function clearBtn_clickHandler(event:MouseEvent):void


      sparkList.selectedIndex = 0;

      mxList.selectedIndex = 0;

      sparkDdl.selectedIndex = 0;

      sparkCbo.selectedIndex = 0;

      mxCbo.selectedIndex = 0;

      if (callLaterCkb.selected)






      private function application1_creationCompleteHandler(event:FlexEvent):void







      <fx:Array id="validatorList">


      <mx:NumberValidator id="sparkListValidator"

      source="{sparkList}" property="selectedIndex"


      requiredFieldError="Spark List is required"

      lowerThanMinError="stateLst index is too small"/>



      <mx:NumberValidator id="mxListValidator"

      source="{mxList}" property="selectedIndex"


      requiredFieldError="MX List is required"

      lowerThanMinError="mxList index is too small"/>




      <mx:NumberValidator id="sparkDropDownListValidator"

      source="{sparkDdl}" property="selectedIndex"


      requiredFieldError="Spark DDL is required"

      lowerThanMinError="sparkDdl index is too small"/>



      <mx:NumberValidator id="sparkComboValidator"

      source="{sparkCbo}" property="selectedIndex"


      requiredFieldError="Spark Cbo is required"

      lowerThanMinError="sparkCbo index is too small"/>



      <mx:NumberValidator id="mxComboListValidator"

      source="{mxCbo}" property="selectedIndex"


      requiredFieldError="MX Combo is required"

      lowerThanMinError="mxCbo index is too small"/>





      <s:ArrayCollection id="stateAc">

      <fx:Object label="NSW" data="N" state_id="0"/>

      <fx:Object label="QLD" data="Q"  state_id="1"/>

      <fx:Object label="VIC" data="V" state_id="2"/>

      <fx:Object label="SA" data="S" state_id="3"/>

      <fx:Object label="ACT" data="A" state_id="4"/>






      <s:Form id="theForm" >

      <s:FormItem label="Spark List">

      <s:List id="sparkList" labelField="label" dataProvider="{stateAc}"/>



      <s:FormItem label="MX List" width="100">

      <mx:List id="mxList" labelField="label" dataProvider="{stateAc}" width="100%"/>



      <s:FormItem label="Spark Drop Down List">

      <s:DropDownList id="sparkDdl" labelField="label" dataProvider="{stateAc}"/>

      <s:ComboBox id="sparkCbo" labelField="label" dataProvider="{stateAc}"/>



      <s:FormItem label="MX Combo">

      <mx:ComboBox id="mxCbo" labelField="label" dataProvider="{stateAc}" editable="false"/>




      <s:HGroup width="100%">

      <s:Button id="okBtn" label="OK" click="okBtn_clickHandler(event)"/>

      <s:Button id="clearBtn" label="Clear" click="clearBtn_clickHandler(event)"/>

      <s:CheckBox id="callLaterCkb" label="Call Later"/>



      <s:Label id="resultLbl"/>