Documentation

Search value is required

Autocomplete

The autocomplete component displays items underneath a input element that match the input value.

Usage


The Autocomplete uses the JQuery UI Autocomplete. Use the single line input element and autocomplete together.

Setup

To use the Autocomplete you must get JQuery and JQuery UI into your project. This can be done in multiple ways:

  1. CDN link
  2. Download src files
  3. npm

The Autocomplete is fully customisable, here is the default behaviour for Standard Life used in this example.

$( '#documentationSearchExample' ).autocomplete({
    classes: {
        'ui-autocomplete' : 'slb-autocomplete'
    },
    source: yourDataSource,
    create: function() {
        $(this).data('ui-autocomplete')._renderItem = function( ul, item ) {
        return $( '<li>' )
            .addClass( 'slb-autocomplete__item' )
            .append( item.label )
            .appendTo( ul );
        };
    }
});

For more information, visit the API Documentation.

Markup: forms\autocomplete.hbs Copy
<form autocomplete="off">
    <div class="slb-form__group" id="documentationExample">
        <input type="text" class="slb-form__control-block" id="documentationSearchExample">
        <label class="slb-form__label" for="documentationSearchExample">Search Programming languages</label>
        <span class="slb-form__bar"></span>
    </div>
</form>
Source: components/forms/_autocomplete.scss