3
votes

I have a combobox implementation as follows - Based on user input (min 2 chars) in the editable combobox, the data provider is refreshed and drop-down opened, showing different data sets as user input varies.

Problem is that after drop-down opens, the cursor moves back to the beginning. So for instance, the user types in "ab", and wants to type in "c" to form the search string "abc". Due to the cursor re-setting its position to 0, the search string instead ends up as "cab".

Here's what I tried already (doesn't work) : textInput.mx_internal::getTextField().setSelection(index, index);

where index = length of user input. This selects text from index to index (which effectively un-selects text) and is supposed to place the cursor at the end.

Any thoughts?

2

2 Answers

4
votes

You're doing the right thing. You just have to make sure that the TextInput has focus before you set the selection index.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">


    <mx:VBox>

        <mx:TextInput id="input" />

        <mx:Button label="set cursor" click="setCursor()" />

    </mx:VBox>

    <mx:Script>
        <![CDATA[

            public function setCursor ():void {
                var index:Number = input.text.length;
                input.setFocus();
                input.mx_internal::getTextField().setSelection(index, index);
            }

        ]]>
    </mx:Script>

</mx:Application>
0
votes

And if you have since moved to Spark (flex 4)

input.selectRange(index, index);