Home > Programming, jQuery > Using ui autocomplete as a dropdown, with type in

Using ui autocomplete as a dropdown, with type in

I had been using an autocomplete plugin by bassistance. 2 months later jQuery UI added autocomplete to their list of widgets. Like many plugins out there I was unable to find an autocomplete that was easy to use for my purposes. The closest I recently came to was the sexy combo plugin. I cant remember why but it was just a tad short of what I wanted to do, and I’m still quite a javascript novice.

I came up with a way to use the jQuery UI autocomplete widget as a <select> that you could also type in something if the choices in the dropdown didn’t fit your needs.

ui-autocomplete-dropdown

This example uses a local data source, but you can come up with creative ways to use remote JSON sources if you like.

<script type="text/javascript">
	$(document).ready(function() {

		// dropdown/ auto suggest
		$(".ui_dropdown").autocomplete({
			minLength: 0,
			delay: 0
		});

		$(".ui_dropdown").click(function(){

			var input = $(this);
			var inputID = input.attr('id');

			// close if already visible
			if (input.autocomplete("widget").is(":visible")) {
				input.autocomplete("close");
				return false;
			}

			// set source(s)
			var myData = '';
			if(inputID == 'input1'){
				myData = ["foo","bar","hello","world"];
			} else {
				myData = ["1","2","3","4"];
			}

			// load source
			input.autocomplete({
				source: myData
			});

			// fire search event
			input.autocomplete("search", "");
			input.focus();
			return false;
		});		

	});
</script>

In this script I am using the input id’s to define the data source.

Categories: Programming, jQuery Tags:
  1. May 7th, 2010 at 19:50 | #1

    Great information was shared in this post…
    Thank you for the post..

  2. March 18th, 2013 at 00:46 | #2

    It is superior to be examining your post Using ui autocomplete as a dropdown, with type in, and who besides will examine it he will absolutely get a lot of supplementary.

  3. September 30th, 2013 at 21:35 | #3

    There are craps players that use a technique reffered to as “dice controll” which alters the probibilities that different numbers will be rolled, shifting the odds into their favor, shoudl they bet accordingly, While it is impossible to measure due to the inneficiency of human action, the ROI for craps is estimated to be as high as 110%. The concept of dice conrrol has never been proven or disproven, but the concept is sound in principal.

  4. October 7th, 2013 at 06:28 | #4

    I have big doubt that many others ask me when i tell them am going to buy new Canvas Hd. How Micromax Make this phone in low price with these features.Why should other leading brand(samsung ,sony..etc.) high price. They think that the quality of Hardware of micromax is very low.

  5. Jonny
    October 30th, 2013 at 15:52 | #5

    uk.bestessays.com is adept at handling any form of writing assignments and I totally vouch for them. I have been using their services for over a year now and I am sure I will keep coming to them time and again.

  6. November 5th, 2013 at 22:07 | #6

    I made an appointment with David and met him at his very nice San Francisco office. I was a little anxious to say the least, but I should not have been. The relief of having shared my financial burden with him was profound. In his confident, take all the time you need demeanor he listened,

  7. December 7th, 2013 at 02:35 | #7

    Thank you for sharing. I am as a Freelance web developer Melbourne has found very useful. Great post.

  8. Anthony
    December 7th, 2013 at 09:58 | #8

    The post is nice. I would like all students to have a look on cheap uni textbooks accounting

  9. December 17th, 2013 at 10:50 | #9

    thank your sharing, I think I will be good practice. Yepi 6 | Friv 10 | Hopy 4

  10. December 19th, 2013 at 10:43 | #10

    I am sure I will keep coming to them time and again.I made an appointment with David and met him at his very nice San Francisco office. I was a little anxious to say the least, but I should not have been. Thank you for sharing.

  11. March 29th, 2014 at 06:14 | #11

    I like this app, it tells me Feeling close to their interface
    would have to take quite some time for the n facilities to its code right? Thank you.

  12. May 12th, 2014 at 02:34 | #12

    watch welcome to the punch watch online gy welcome to the punch online IiUi welcome to the punch onine free

  13. June 18th, 2014 at 02:25 | #13

    It was a great read which was extremely helpful.
    friv 4

  14. July 21st, 2014 at 05:07 | #14

    I saw what you said is very good and it is very useful for me in life, thanks.
    Friv 6

  15. friv 3
    August 5th, 2014 at 21:18 | #15

    What’s even more comfortable when you are entertaining after a day of hard work.
    friv 3

  16. Jame
    August 26th, 2014 at 20:56 | #16

    Like many plugins out there I was unable to find an autocomplete that was easy to use for my purposes.
    Friv

  17. September 3rd, 2014 at 03:42 | #17

    you always bring everyone the most interesting and useful, I like it all, thank you.

  18. October 1st, 2014 at 03:55 | #18

    If you still have no idea what this means, don’t worry about it, because you can always…

  19. October 27th, 2014 at 21:20 | #19

    you always bring everyone the most interesting and useful, I like it all, thank you.

  20. November 15th, 2014 at 15:36 | #20

    A cash enhance would be a packed with cash borrowed against your borrowing limit. you will be able to confiscate a cash enhance in 2 that at intervals that. First, by exploitation you’re PIN at honor ATM. Or, you will be able to use a convenience certify your credit score cards supplier sent to you.

  1. April 1st, 2010 at 10:31 | #1
  2. April 1st, 2010 at 11:10 | #2
  3. April 1st, 2010 at 11:28 | #3
  4. April 1st, 2010 at 11:36 | #4
  5. April 1st, 2010 at 11:50 | #5
  6. April 1st, 2010 at 11:54 | #6
  7. April 1st, 2010 at 12:03 | #7
  8. April 1st, 2010 at 12:09 | #8
  9. April 1st, 2010 at 12:11 | #9
  10. April 1st, 2010 at 12:16 | #10
  11. April 1st, 2010 at 12:27 | #11
  12. April 1st, 2010 at 12:28 | #12
  13. April 1st, 2010 at 12:28 | #13
  14. April 1st, 2010 at 14:09 | #14
  15. April 1st, 2010 at 14:46 | #15
  16. April 1st, 2010 at 14:54 | #16
  17. April 1st, 2010 at 15:24 | #17
  18. April 1st, 2010 at 15:33 | #18
  19. April 8th, 2010 at 15:09 | #19