Creating an autocomplete text input
On our web forms, there may be times when we want to have an autocomplete text field. This can be handy for populating common search terms or product names. Using the jQueryUI Autocomplete library along with Laravel, that becomes an easy task.
Getting ready
In this recipe, we'll be using the CDN versions of jQuery and jQueryUI; however, we could also download them and place them in our public/js
directory, if we wanted to have them locally.
How to do it...
To complete this recipe, follow these steps:
Create a route to hold our autocomplete form:
Route::get('autocomplete', function() { return View::make('autocomplete'); });
Make a view in the
app/views
directory namedautocomplete.php
with our form's HTML and JavaScript:<!DOCTYPE html> <html> <head> <title>Laravel Autocomplete</title> <meta charset="utf-8"> <link rel="stylesheet"href="//codeorigin.jquery.com/ui/1.10.2/themes/smoothness/jquery...