Maybe try using Selection.getCaretIndex() as the input_length?

 

Matt

 


From: [email protected] [mailto:[email protected]] On Behalf Of [EMAIL PROTECTED]
Sent: Wednesday, November 09, 2005 8:39 AM
To: [email protected]
Subject: [flexcoders] Cursor position in editable ComboBox

 

Hi List,

I try to code a auto complete ComboBox. It nearly woks, I give you my code:

<?xml version="1.0" encoding="UTF-8"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml">

    <mx:Script>
        <![CDATA[

            var my_select;

            function completeComboBox(){
                var input_length = brand.value.length;
                for(var i=0; i < brands.brand.length; i++){
                        if(brands.brand[i].substr(0,input_length) ==
brand.value.toUpperCase().substr(0,input_length)){
                            brand.text = brands.brand[i];
                            break;
                        }
                }
            }

        ]]>
    </mx:Script>

   <mx:Model id="brands" source="brands.xml" />

    <mx:Panel width="100%" height="100%">

        <mx:Form width="100%" height="100%">

            <mx:FormItem label="brand">
                <mx:ComboBox id="brand" dataProvider="{brands.brand}"
editable="true" change="completeComboBox()" />
            </mx:FormItem>

        </mx:Form>

        <mx:TextArea text="{my_select}" width="100%" height="25%"></mx:TextArea>

    </mx:Panel>

</mx:Application>

If I type only one character, the completion works well. The problem is a user
input longer than one character.
I'll give you an example. Lets say I'm searching for the brand "Mercedes-Benz".
I type M, auto completion is executed and there is "Malaguti" in the editable
ComboBox. The cursor is behind the "M". I search for "Mercedes-Benz" and type
"e". The "e" is inserted at the cursor position and there is "Mealaguti" in the
ComboBox.
Is there any possibility to cut off everything which is behind the cursor, so
the auto completion only uses characters I typed in?

Any thougt is appreciated.
Christoph



--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com




YAHOO! GROUPS LINKS




Reply via email to