Dan Monego
Dan Monego

Reputation: 10087

Flex: Changing Control Properties based on contents of a Databinding event

I'm trying to set up a form that presents a combobox when an ArrayCollection it's bound to has several items, and doesn't present one when it's empty or only has one item. I've tried doing this by creating this class, but unfortunately, the data provider I've bound to is never not empty at the time the setter executes. Is there a different way I should approach this?

public class ComboboxOrFail extends ComboBox
{
    public function ComboboxOrFail()
    {
        super();
    }

    public override function get dataProvider():Object
    {
        return super.dataProvider;
    }

    public override function set dataProvider(value:Object):void
    {
        this.visible = (value && value.length && value.length > 1);
        super.dataProvider = value;
    }
}

Upvotes: 1

Views: 96

Answers (1)

Doug Hays
Doug Hays

Reputation: 1507

I've done this in a different way:

<mx:ComboBox dataProvider="{myData}" visible="{myData != null &amp;&amp; myData.length > 1}"/>

Assuming that myData is bindable, this should do the trick!

Upvotes: 1

Related Questions