86488

jQuery UI Autocomplete Partial Match

Question:

I am trying to make the jQuery UI Autocomplete search only the first few letters of my strings. I thought I could do a key/ value thing with jQuery UI, but I am not sure if that applies.

I have the following string:

AGREE Agreement by and between BLANK, in BLANK, of the county records.

Only AGREE should be searched, not the rest of the string. AGREE is the text-code that the user will search for.

Here is my simple code:

var availableTags = [ "AGREE Agreement by and between BLANK, in BLANK, of the county records.", "CONDO Covenants, conditions, restrictions, reservations, terms, provisions, easements, liens for assessments, options, powers of attorney and limitations on title as set forth in the Ohio Revised Code Chapter 5311, or as set forth in the Declaration of Condominium ownership and Bylaws as recorded in BLANK, as amended, plat BLANK, of the county records." ]; $( "#tags" ).autocomplete({ source: availableTags });

Only the first words AGREE and CONDO should be searched, not the rest of the strings. Is this possible/ feasible?

Answer1:

If you're only searching for the tags then why don't you just put the tags in the array?

Answer2:

My solution was this:

<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>autocomplete demo</title> <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css"> <script src="http://code.jquery.com/jquery-1.9.1.js"></script> <script src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script> </head> <body> <label for="autocomplete">Select a programming language: </label> <input id="autocomplete"> <script> var tags = [ "c++", "java", "php", "coldfusion", "javascript", "asp", "ruby" ]; $( "#autocomplete" ).autocomplete({ source: function( request, response ) { var matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( request.term ), "i" ); response( $.grep( tags, function( item ){ return matcher.test( item ); }) ); } }); </script> </body> </html>

Ref. <a href="http://api.jqueryui.com/autocomplete/#event-search" rel="nofollow">http://api.jqueryui.com/autocomplete/#event-search</a> (bottom of the page)

Recommend

  • Combine similar XML records/fields with XSL
  • D3 Map - feeding data to tootip
  • What am I doing wrong with this NSMutableArray of structs in NSUserDefaults? “attempt to insert non-
  • How To Set The Correct RadioButton.IsChecked Property True By Binding To A ViewModel?
  • Saving the “state” of a Z3 solver in SMT2 format
  • Bigcommerce Stencil Custom Handlebars “Replace” Helper
  • Numpy array indexing and/or addition seems slow
  • Cleaning a large text file
  • Read uncomitted data from HasMany-relationship with NHibernate
  • Implementing BootstrapNotifier on Activity instead of Application class
  • Replace individual symbols in a set
  • Add an md5 hash value to a big CSV file
  • Inno Setup Copy Files and Folders to an Existing Zip File
  • Ninject and Custom Controller Factory
  • Mac System Services - application “(null)”
  • Inserting an element into a sorted list
  • How to redirect to custom URI scheme, or show some content if not supported?
  • Write two-dimensional list to JSON file
  • How does C handle EOF? [duplicate]
  • Using list comprehension instead of for loop when working with Django QuerySets
  • Deleting entire row on criteria cannot handle 400,000 rows
  • .NET Obfuscation [SmartAssembly]
  • Android multuple camera preview
  • C Language: Why does malloc() return a pointer, and not the value?
  • Using LINQ with IBM i
  • draw a B+ tree in latex
  • how to automatically enter password when using ssh?
  • possible limitation of implode function in PHP
  • How to load gif image while ajax content is loading and javascript [duplicate]
  • MongoDB in PHP using aggregate to group by _id is null not working
  • Display issues when we change from one jquery mobile page to another in firefox
  • To display the title for the current loaction in map in iphone
  • trying to dynamically update Highchart column chart but series undefined
  • How to set the response of a form post action to a iframe source?
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • Change div Background jquery
  • Qt: Run a script BEFORE make
  • How can I remove ASP.NET Designer.cs files?
  • reshape alternating columns in less time and using less memory
  • java string with new operator and a literal