Link to home
Start Free TrialLog in
Avatar of Newbster
Newbster

asked on

Flex autocomplete in textarea

I want to add an autocomplete feature into a textarea using a custom tooltip. As the user type in the textarea, a tooltip will popup with a list of "like words or phrase", and the user can click on the word or phrase to output it in the textarea.(kind of like the t9 feature on a mobile phone)
Avatar of IqAndreas
IqAndreas
Flag of Sweden image

I haven't tried any of these components yet, but they are worth taking a look at:
http://developer.yahoo.com/flash/astra-flash/autocomplete/
http://blogs.adobe.com/sho/archives/2006/04/new_version_of.html
http://hillelcoren.com/flex-autocomplete/

If you end up giving them a try, please share your results with us. :)

Good luck with your programming,
Andreas
Avatar of Newbster
Newbster

ASKER

Actually, I tried those autocomplete solutions already... it only works for single line. I need something for a textarea.
Ah, I see.

How good are you with ActionScript? If you feel your are up for the challenge, you can use an "auto complete framework" such as one of the ones I provided links for, and instead listen for when text changes on the TextArea.

When it does, you can detect the current cursor position with "the_text_area.textField.caretIndex"
http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/text/TextField.html#caretIndex
Then you can use various string commands such as "substring()" or "charAt()" to find out which letters the users have already typed
http://help.adobe.com/en_US/AS3LCR/Flash_10.0/String.html

Then manually call the autocomplete libraries using this information, and find out which words are likely picks.


Do you understand the process I am recommending? Is there any part of it you want me to explain in more detail?

Good luck with your programming,
Andreas
Thanks for the quick response, I was thinking about something like that too, but the current autocomplete(the one from the links above)  is a extended from a combobox. I would like ithe dropdown to be right under the text (under current cursor position). The only way I can think of is to use  a custom tooltip bc it can popup at any position on the page.

Tooltip issue so far:
1. cursor position = to the textarea position ... not the x and y of the page ... so I cant position the tooltip under the cursor
2. cant (note sure how to) execute a custom tooltip with components  through "change" event ... I can open default tool tip using Tooltipmanager

Thanks
ASKER CERTIFIED SOLUTION
Avatar of IqAndreas
IqAndreas
Flag of Sweden image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
cool thx
I extended the TextArea to get into the protected Textfield.

x  = TextArea.Textfield.getCharboundaries( TextArea.textfield.caretIndex-1).x;
y = TextArea.Textfield.getCharboundaries( TextArea.textfield.caretIndex-1).y;

I got that workin thanks to you...

Now, I need to somehow add components(gridbox) to the tooltip using TooltipManager.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I can draw shapes on the sprite and it will be visible, but when I add a component to sprite, it is not visible.

code:
var but:Button = new Button();
but.width = 100;
but.label = "sdfdsf";

sprite = new Sprite();
sprite.x = inputX;
sprite.y = inputY+20;
sprite.addChild(but);

textarea.addChild(sprite);
Don't add it as a child of the TextArea. Instead, add it directly to the stage or whatever sprite is your main document class.

Also, make sure you don't mix up local coordinates and global ones. Are you experienced enough with ActionScript to know the difference?

I'm also not sure if TextArea is a DisplayObjectContainer (meaning it can hold other items). I know the TextField DEFINITELY isn't a container. Try adding it as a "sibling" instead of a child. It will make things a lot easier.

Do you understand how to do this, or do you need some actual ActionScript for it?
I just got it working... i added it to a container... the sprite is position where i wanted as i type in the text area... so next up ... autocomplete functionality, but i got it from here .... thx for ur help.

This is how i did the coordinate:

var inputX:Number = a.myTextField.getCharBoundaries(a.myTextField.caretIndex - 1).x;
var inputY:Number = a.myTextField.getCharBoundaries(a.myTextField.caretIndex - 1).y;

 coorX = event.currentTarget.x + inputX;
 coorY = event.currentTarget.y + inputY  +20;