Flex dispatchEvent to exit an ItemEditor

164 views Asked by At

I have an ItemEditor with a ComboxBox. To improve user experience, I would like to exit the ItemEditor each time the user select a value in the combobox. So he doesn't have to click outside the cell to validate his choice.

I did this, but it is not working. Why ?

        private function comboChange(event:IndexChangeEvent):void
        {
            var dgOrder:DataGrid = owner as DataGrid;
            var dgEvent:GridEvent = new GridEvent(GridEvent.GRID_CLICK);
            dgEvent.preventDefault();
            dgOrder.dispatchEvent(dgEvent);

        }
    ]]>
</fx:Script>

<s:ComboBox id="ddlCurrency" width="100%" dataProvider="{lstCurrencies}" labelField="CurrencyCode" 
            prompt="Select a currency" change="comboChange(event)"></s:ComboBox>

EDIT after Marcx comment :

override public function get value():Object {
                trace("get value");
                ddlCurrency.selectedIndex = newCountryID;
            if (ddlCurrency.selectedIndex == -1 || ddlCurrency.selectedItem.CurrencyID == -1){
                updateCurrency(data.OrderID, -1);
                return "";
                } else if ((lstCurrencies[ddlCurrency.selectedIndex as int] as Object).CurrencyCode.toString() != ddlCurrency.selectedItem.CurrencyCode){
                    return oldValue;
                } else {
                    updateCurrency(data.OrderID, ddlCurrency.selectedItem.CurrencyID);
                    return ddlCurrency.selectedItem.CurrencyCode;
                }
            }

private function comboChange(event:IndexChangeEvent):void
            {
                var dgOrder:DataGrid = owner as DataGrid;
                newCountryID = ddlCurrency.selectedIndex;
                dgOrder.setFocus();
            }

When I select a value on the dropdownList (it was a combobox before), combochange is called and the ddlCurrency.selectedIndex is the one I have just selected, and once the get value() function is called the same ddlCurrency.selectedIndex is the previous index. It why I save the new Index in a variable to force the new index in get value().

I hope I made my self clear.

Thanks in advance. Antoine.

1

There are 1 answers

2
Marcx On

You can try setting the focus on the parent element or directly the application...

private function comboChange(event:IndexChangeEvent):void
{
    var dgOrder:DataGrid = owner as DataGrid;
    var dgEvent:GridEvent = new GridEvent(GridEvent.GRID_CLICK);
    dgEvent.preventDefault();
    dgOrder.dispatchEvent(dgEvent);
    // set the focus on the owner component
    dgOrder.setFocus();             
}

From the as3docs:

spark.components.DataGrid.setFocus():void

[Inherited] Sets the focus to this component. The component can in turn pass focus to a subcomponent.

Note: Only the TextInput and TextArea controls show a highlight when this method sets the focus. All controls show a highlight when the user tabs to the control.