简体   繁体   中英

Flex editable combobox

I am using editable combobox for my application. Combobox have default behavior like

If I enter some text which is not similar to the combobox dataprovider values, combobox by default select first dataprovider value and close the dropdown window. I want stop this default behavior.

Ex. I have combobox with the dataprovider value. (stack, stackoverflow, stackoverflow A) I open the dropdown and see the "stackoverflow A" value is in the dropdown. Now I enter value "stackoverflow B" but this value is not in the dropdown so when I enter, combobox override my entered text and replace "stackoverflow B" with first value of dataprovider(dropdown) "stack" and fire the selectedindex change event. I want to stop default behavior of combobox of selection of first value by default and look for entered value.

I have tried doing selectedindex to -1 by default but its still taking the first value by default. Any work around or suggestion would be helpful.

thanks

There is an alternative to the <s:ComboBox> which does not attempt to match text with the data provider values (as described above), and does not have this bug . It is an ActionScript, Flex, spark only combo box, and is available as open source .

I think this will gonna be helpful to you...

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" horizontalAlign="center" 
verticalAlign="middle" height="100%" width="100%">

<mx:Script>
    <![CDATA[
        public var arr:Array = new Array({isSelected:true,label:'ABC',score:'78',name:'ABC'},
                                         {isSelected:true,label:'DEF',score:'50',name:'DEF'},
                                         {isSelected:false,label:'GHI',score:'70',name:'GHI'},
                                         {isSelected:false,label:'JKL',score:'80',name:'JKL'},
                                         {isSelected:true,label:'TRE',score:'50',name:'MNO'});

        public function dgCLG_dataChange():void
        {

        }

        public function dgCLG_change():void
        {

        }

        public function btnSubmit_click():void
        {
            dgCopy.dataProvider = dgCLG.dataProvider;
        }

    ]]>
</mx:Script>

<mx:VBox height="100%" width="100%" horizontalAlign="center" verticalAlign="middle">
    <mx:DataGrid id="dgCLG" dataProvider="{arr}" editable="true" dataChange="{dgCLG_dataChange();}" change="{dgCLG_change();}">
        <mx:columns>
            <mx:DataGridColumn headerText="" dataField="isSelected">
                <mx:itemRenderer>
                    <mx:Component>
                        <mx:Box horizontalAlign="center" verticalAlign="middle" height="100%" width="100%">
                            <mx:Script>
                                <![CDATA[
                                    override public function set data(value:Object):void
                                    {
                                        if(value != null)
                                        {
                                            super.data = value;
                                            var temp:Object = value as Object;
                                            chb.selected = temp.isSelected;
                                        }
                                    }
                                ]]>
                            </mx:Script>
                            <mx:CheckBox id="chb"/>
                        </mx:Box>
                    </mx:Component>                     
                </mx:itemRenderer>
            </mx:DataGridColumn>
            <mx:DataGridColumn headerText="Label" dataField="label" editable="false">

            </mx:DataGridColumn>
            <mx:DataGridColumn dataField="name" headerText="Person" itemEditor="ComCB" editorDataField="value" editable="true">

            </mx:DataGridColumn>
        </mx:columns>
    </mx:DataGrid>  

    <mx:Button id="btnSubmit" label="Click" click="{btnSubmit_click();}" />

    <mx:DataGrid id="dgCopy" editable="false">
        <mx:columns>
            <mx:DataGridColumn headerText="CopyLabel" dataField="label" />
            <mx:DataGridColumn headerText="CopyMarks" dataField="score" />
            <mx:DataGridColumn headerText="CopyPerson" dataField="name" />
        </mx:columns>
    </mx:DataGrid>
</mx:VBox>

</mx:Application>

Here is the ComCb Component.

<?xml version="1.0" encoding="utf-8"?>
<mx:ComboBox xmlns:mx="http://www.adobe.com/2006/mxml" dataProvider="{arr}" selectedIndex="1" creationComplete="{c_complete();}" >
<mx:Script>
    <![CDATA[
        public var arr:Array = new Array({label:'ABC'},{label:'DEF'},{label:'GHI'},{label:'JKL'},{label:'MNO'},{label:'XXX'})

        public function c_complete():void
        {
            for(var i:int = 0; i < arr.length; i++)
            {
                if(arr[i].label == parentDocument.dgCLG.selectedItem.name)
                {
                    this.selectedItem = arr[i];
                }
            }   
        }
    ]]>
</mx:Script>
</mx:ComboBox>

might be this will gonna helpful to you...

Have a NICE D@y.......

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM