Set initial state in combobox

When this form is loaded, my combobox always has the first name in the arraycollection displayed. I tried setting the selectedIndex = -1 right there in the form, and onCreationComplete setting it to -1.

But I still see the first value being sent to the server. How can I change my combobox to be set to -1 only on initial page load. I have a button that calls a _clear() method, which sets it all to -1 and it behaves as I would expect. Just need to mimic this behavior when anyone navigates to this tab.
<mx:FormItem direction="horizontal" label="District:">
		<mx:ComboBox
			id="districts" 
			labelField="name" 
			dataProvider="{districtCollection}" 
			selectedIndex="-1"
			change="onDistrictSelected(event);submit()"/>
</mx:FormItem>

Open in new window

hallikpapaAsked:
Who is Participating?
 
Jones911Connect With a Mentor Commented:
But that's the array collection

Swap this:  analyticsView.districtCollection.selectedIndex = -1;
For:  districts.selectIndex = -1;
0
 
Jones911Commented:
selected = false;
<mx:ComboBox
                        id="districts" 
                        labelField="name" 
                        dataProvider="{districtCollection}" 
                        selected = false;
                        change="onDistrictSelected(event);submit()"/>

Open in new window

0
 
hallikpapaAuthor Commented:
I got an error:

Cannot resolve attribute 'selected' for component type mx.controls.ComboBox.
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Jones911Commented:
My bad I read checkbox :(

In the event handler where you set arrayCollection

do districts.selectIndex = -1; after you have set up the arrayCollection.  The change event on the array collection changes it.
0
 
hallikpapaAuthor Commented:
I have a case statement that's handle this, and I get this error on the selectedIndex = -1; line:

1119: Access of possibly undefined property selectedIndex through a reference with static type mx.collections:ArrayCollection.

case ApplicationFacade.DISTRICT_SUCCESS:
	analyticsView.districtCollection = this._districtProxy.districts;
		   			         analyticsView.districtCollection.selectedIndex = -1;
break;

Open in new window

0
 
hallikpapaAuthor Commented:
Yeah I noticed that. I forgot to put analyticsView in front of districts. Oops. :)

So I do this:
analyticsView.districts.selectedIndex = 2;

And it submits a 2, as expected. But when I do this:

analyticsView.districts.selectedIndex = -1;

It submits a 0. It's weird cause when that combobox changes, onDistrictSelected(event) is called. And in there I do this:

analyticsView.stations.selectedIndex = -1;

and that is correctly set to -1 instead of 0???


0
 
Jones911Commented:
-1 is nothing 0 is the first element.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.