How to set flex combobox cursor position

I have a combobox implementation as follows. Based on user input (min 2 chars) in an editable combobox, the data provider is updated and a drop-down list opens showing different data sets depending on user input.

The problem is that after the drop-down list, the cursor returns to the beginning. So, for example, the user enters "ab" and wants to enter "c" to form the search string "abc". Due to the cursor resetting its position to 0, the search bar instead ends with a “cab”.

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

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

Any thoughts?

+3
source share
2 answers

You are doing the right thing. You just need to make sure that TextInput has focus before setting the select 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>
+4
source

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

input.selectRange(index, index);
0
source

Source: https://habr.com/ru/post/1737431/


All Articles