Autocompleter

A Laravel library with Javascript JQuery script to add input with auto-completer. Current version: 1.5.0. Project on GitHub. Project on Packagist. This demosite sources available here.


$ac = AutocompleterHelper::init(
  'autocompleter1', //id
  'Countries', //label
  route('autocompletesearch'), // route called when typing in input
  [
    'callback' => 'output', // js callback called after selecting element
    'id_included' => false, // id column not added in item list
  ]
);
return view('template', ['ac' => $ac]);

Then print your autocompleter by inserting {!! $ac !!} in your template. Javascript code to be inserted in blade template:


<script type="text/javascript">
var output = function(data){ //function called after an element is selected in list
  jQuery('#result').val(
    (jQuery('#result').val().length > 0 ? jQuery('#result').val()   + "\n#"  : '#' )
    + data.id + ': ' + data.country
  );
}
</script>

Demo

Type some characters to select a country. Results will be added to above list.

    Type search terms, select element with arrows and validate with Enter or use mouse

    Results