?
Solved

Set initial state in combobox

Posted on 2009-02-20
7
Medium Priority
?
786 Views
Last Modified: 2013-11-11
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

0
Comment
Question by:hallikpapa
  • 4
  • 3
7 Comments
 
LVL 19

Expert Comment

by:Jones911
ID: 23696168
selected = false;
<mx:ComboBox
                        id="districts" 
                        labelField="name" 
                        dataProvider="{districtCollection}" 
                        selected = false;
                        change="onDistrictSelected(event);submit()"/>

Open in new window

0
 

Author Comment

by:hallikpapa
ID: 23696256
I got an error:

Cannot resolve attribute 'selected' for component type mx.controls.ComboBox.
0
 
LVL 19

Expert Comment

by:Jones911
ID: 23696338
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:hallikpapa
ID: 23696425
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
 
LVL 19

Accepted Solution

by:
Jones911 earned 2000 total points
ID: 23696486
But that's the array collection

Swap this:  analyticsView.districtCollection.selectedIndex = -1;
For:  districts.selectIndex = -1;
0
 

Author Comment

by:hallikpapa
ID: 23696947
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
 
LVL 19

Expert Comment

by:Jones911
ID: 23697559
-1 is nothing 0 is the first element.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is intended to introduce all collision detection principles in flash, their strengths, weaknesses and workarounds. The main method for Collision Detection in flash is using hitTestObject. But unless you'll be pushing rectangular shapes without …
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.
Suggested Courses
Course of the Month17 days, 10 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question