I had a similar issue, where the validation/redbox error was being 
fired off when i didnt want it to be.

this is the way i see it.

your validator is monitoring combobox.selectedIndex ie

<mx:Model id="validationModel">
    <facilityType>{facilityType.selectedIndex}</facilityType>
</mx:Model>

So everytime your selectedIndex changes (like in a modelChanged) you 
trigger validation..........Therefore, don't monitor selectedIndex.

You could try the following - 
Create an extended combobox with an extra property called 'myIndex'. 
And monitor that i.e.

<mx:Model id="validationModel">
    <facilityType>{facilityType.myIndex}</facilityType>
</mx:Model>

myIndex would be updated with the selectedIndex value during the 
combobox change event.
eg

<mx:ComboBox change="doChange(event)">
<mx:Script>

var __myIndex:Number;
[ChangeEvent("mychanged")]
function get myIndex():Number
{
  return __myIndex;
}

function set myIndex(txt:Number):Void
{
  __myIndex = txt;

  dispatchEvent({type:"myChanged"});
}

function doChange(event){
myIndex = selectedIndex;
}

its a bit long winded but it should give you some ideas.
(and the code is untested).




--- In flexcoders@yahoogroups.com, "Tim Dwelle" <[EMAIL PROTECTED]> wrote:
> The prompt property helps simplify things a bit, but doesn't solve 
the 
> problem.
> 
> In fact, it seems to create its own problem.  When I use the 
prompt in 
> conjunction with a combobox using the data provider / 
labelField... it now 
> highlights the first 2 options (the prompt and the first option 
from the 
> webservice) whenever item 0 is selected!  Works like a champ when 
the 
> combobox has all string items, though...
> 
> Regardless of that cosmetic issue, the real problem is that the 
modelChanged 
> event (I'm guessing that is the one) seems to also trigger 
validation. So 
> even though we aren't firing off a change event because we won't 
have to set 
> the selectedIndex, we are still triggering validation when the 
combobox gets 
> populated.
> 
> That's the bit I'm trying to avoid. I don't want the box to turn 
red until 
> the user actually makes a selection, or when we call 
isSelectionValid(). Any 
> ideas?
> 
> Thanks again.
> 
> -Tim.
> 
> >From: "Matt Chotin" <[EMAIL PROTECTED]>
> >Reply-To: flexcoders@yahoogroups.com
> >To: <flexcoders@yahoogroups.com>
> >Subject: RE: [flexcoders] bypass the change event
> >Date: Wed, 22 Jun 2005 22:38:28 -0700
> >
> >What if you used the ComboBox prompt property instead and only 
set the
> >selectedIndex if you have a real value?  It might avoid the 
change event
> >firing there too.
> >
> >
> >
> >Matt
> >
> >
> >
> >________________________________
> >
> >From: flexcoders@yahoogroups.com 
[mailto:[EMAIL PROTECTED] On
> >Behalf Of dwellet
> >Sent: Wednesday, June 22, 2005 1:43 PM
> >To: flexcoders@yahoogroups.com
> >Subject: [flexcoders] bypass the change event
> >
> >
> >
> >I have this combobox.
> >
> >The combobox is populated by a webservice.
> >
> >When the webservice result arrives, I have a utility function that
> >adds a 'Pick an item...' sort of option at the top of the 
dropdown,
> >and then selects the appropriate selected item.  If there is no
> >appropriate selected item, it picks index 0 (the dummy 'Pick an
> >item...').
> >
> >I have a validator that validates that the combobox has a real
> >selection.
> >
> >The problem is... I want my utility function to happen 
in "stealth"
> >mode. If the user changes the combobox, I want it to be 
validated. But
> >if I programatically set the selectedIndex, I don't want any 
events to
> >fire and trigger validation.
> >
> >Ironically, I read that in Flex 1.0, changing the selectedIndex 
did
> >not fire a change event, but this was "fixed" in 1.5. The old 
behavior
> >is precisely what I want. Any way to temporarily bypass that 
change
> >event firing?
> >
> >Code included below... Thanks for your help!
> >
> >-Tim.
> >
> >
> >
> >
> >[ComboBoxValidator.as]
> >
> >
> >import mx.controls.*;
> >import mx.validators.*;
> >
> >/* ComboBoxValidator
> >*
> >* Validate that a user does not select the dummy option (eg.
> >* 'Pick a value...') in a required combobox.
> >*
> >*/
> >class ComboBoxValidator extends Validator
> >{
> >    public function doValidation(foo:String) : Void
> >    {
> >       var n = Number(foo);
> >       if (n == 0)
> >       {
> >          validationError("noSelection", "Field is required.", 
null);
> >       }
> >    }
> >}
> >
> >
> >
> >
> >
> >[Test.mxml]
> >
> >
> ><mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml";
> >                 xmlns:dom="*"
> >                 creationComplete="start()">
> >
> >     <mx:Script>
> >     <![CDATA[
> >         import mx.controls.*;
> >         import mx.containers.*;
> >         import mx.managers.*;
> >         import mx.validators.*;
> >
> >         import com.dom.sampling.vo.*;
> >
> >         var model : SampleSite;
> >
> >         var PICK_A_FACILITY_TYPE : FacilityType;
> >
> >         /* start()
> >          *
> >          * Perform basic setup.
> >          *
> >          */
> >         function start()
> >         {
> >             PICK_A_FACILITY_TYPE      = new FacilityType();
> >             PICK_A_FACILITY_TYPE.name = "Choose a facility 
type...";
> >             service.getAllFacilityTypes();
> >
> >             if (!model)
> >             {
> >                 model = new SampleSite();
> >             }
> >         }
> >
> >         /* prepareCombobox()
> >          *
> >          * Prepares a combobox by adding a first, descriptive
> >          * option (eg. 'Pick a value...') to the dropdown. It
> >          * also sets the initial value of the combobox, either
> >          * to the item matching the passed in initialValue, or
> >          * if no match is found, to the first item in the
> >          * combobox.
> >          *
> >          * @param combobox      the combobox to prepare
> >          *
> >          * @param pickAValue    the first, descriptive option
> >          *                      (eg. 'Pick a value...') to add
> >          *                      to the combobox
> >          *
> >          * @param initialValue  the initialValue the combobox
> >          *                      should be set to
> >          */
> >         public function prepareComboBox(combobox: ComboBox,
> >                                         pickAValue: Object,
> >                                         initialValue: Object) : 
Void
> >         {
> >             if (pickAValue)
> >             {
> >                 combobox.addItemAt(0, pickAValue);
> >                 combobox.selectedIndex = 0;
> >             }
> >
> >             if (initialValue)
> >             {
> >                 for (var i=0; i < combobox.length; i++)
> >                 {
> >                     var item = combobox.getItemAt(i);
> >
> >                     // object
> >                     if (item instanceof Object &&
> >                         item.id == initialValue.id)
> >                     {
> >                         combobox.selectedIndex = i;
> >                     }
> >
> >                     // non-object
> >                     else if (item == initialValue)
> >                     {
> >                         combobox.selectedIndex = i;
> >                     }
> >                 }
> >             }
> >         }
> >
> >     ]]>
> >     </mx:Script>
> >
> >     <mx:WebService id="service"
> >                    wsdl="/sampling-ws/services/LocationService?
wsdl"
> >                    showBusyCursor="true">
> >
> >         <mx:operation name="getAllFacilityTypes"
> >                       result="prepareComboBox(facilityType,
> >PICK_A_FACILITY_TYPE, model.facilityType)"/>
> >
> >     </mx:WebService>
> >
> >     <mx:Panel title="Administer Sample Site" width="100%">
> >         <mx:FormItem width="100%" required="true" label="Facility
> >Type">
> >             <mx:ComboBox id="facilityType"
> >dataProvider="{service.getAllFacilityTypes.result}"
> >labelField="name"/>
> >         </mx:FormItem>
> >     </mx:Panel>
> >
> >     <mx:Model id="validationModel">
> >         <facilityType>{facilityType.selectedIndex}</facilityType>
> >     </mx:Model>
> >
> >     <dom:ComboBoxValidator required="true"
> >field="validationModel.facilityType"/>
> >
> ></mx:Application>
> >
> >
> >
> >
> >
> >________________________________
> >
> >Yahoo! Groups Links
> >
> >*    To visit your group on the web, go to:
> >     http://groups.yahoo.com/group/flexcoders/
> >
> >*    To unsubscribe from this group, send an email to:
> >     [EMAIL PROTECTED]
> ><mailto:[EMAIL PROTECTED]
subject=Unsubscribe>
> >
> >*    Your use of Yahoo! Groups is subject to the Yahoo! Terms of
> >Service <http://docs.yahoo.com/info/terms/> .
> >




--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to