[ 6 posts ]

bdicasa

  • Joined: Sun Sep 04, 2011 10:11 am
  • Posts: 5
  • Offline
  • Profile

AutoComplete - How to clear input box?

Post Posted: Wed Jun 20, 2012 6:12 am
+0-
Hey guys,

I'm trying to empty a text box with AutoComplete plugged in. I want to empty the text box after the user has made an auto complete selection.

I thought doing this would work:

var testText = Y.one('#test-text').plug(Y.Plugin.AutoComplete);

testText.ac.on('select', function(e) {
testText.set('value', '');
});

However, the text box is not being cleared, and no error is being thrown.

I have a complete JSFiddle example at : http://jsfiddle.net/bdicasa/XkExx/2/

If anyone has any ideas on how to accomplish this, I would appreciate the help.

Thanks,

Brian

bdicasa

  • Joined: Sun Sep 04, 2011 10:11 am
  • Posts: 5
  • Offline
  • Profile

Re: AutoComplete - How to clear input box?

Post Posted: Wed Jun 20, 2012 6:39 am
+0-
I'm currently working around this by setting a timeout in the select event and then clearing the textbox in the timeout. However it doesn't seem like the cleanest solution to the problem.

MaurycyG

  • Joined: Thu Nov 10, 2011 6:17 am
  • Posts: 3
  • Offline
  • Profile

Re: AutoComplete - How to clear input box?

Post Posted: Wed Jun 20, 2012 7:29 am
+0-
It works fine for me,
after keypress i get suggested list, then i choose something and text-box value is replaced with what i choosed,

what is your desired action?

Alberto Santini

YUI Contributor

  • Offline
  • Profile
Tags:

Re: AutoComplete - How to clear input box?

Post Posted: Wed Jun 20, 2012 7:46 am
+1-
Hello bdicasa.

You need to use after:
http://jsfiddle.net/XkExx/3/

Anyway I second MaurycyG's question.

It seems to me quite useless the autocomplete if you clear the selection.

Maybe I didn't understood your issue.

Regards,
IceBox

bdicasa

  • Joined: Sun Sep 04, 2011 10:11 am
  • Posts: 5
  • Offline
  • Profile

Re: AutoComplete - How to clear input box?

Post Posted: Wed Jun 20, 2012 9:55 am
+0-
Thanks for the help guys, that is a much better solution.

The reason I want to clear the text box after selection is that I'm appending the selected item to my GUI and want to allow the user to start typing a different item after selection. Probably not the most common use case, but it is turning out to be pretty slick. :)

Alberto Santini

YUI Contributor

  • Offline
  • Profile

Re: AutoComplete - How to clear input box?

Post Posted: Wed Jun 20, 2012 10:47 am
+0-
Hello bdicasa.

If you need multiple selection you may use delimeters.

See the example:
http://yuilibrary.com/yui/docs/autocomp ... gging.html

Then you may add a sort of undo, just in case the user adds the wrong selection, and, when the user confirms the selections, eventually add the selected text to the gui.


My two cents,
IceBox
  [ 6 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum