ch.Autocomplete
Description
Autocomplete widget shows a list of suggestions for a HTMLInputElement.
How-to
// Create a new AutoComplete with configuration.
var autocomplete = $el.autocomplete();
Parameters
-
$el
- jQuerySelector | ZeptoSelector : A jQuery or Zepto Selector to create an instance of ch.Autocomplete. -
options
- Object : Options to customize an instance.-
loadingClass
- String : Default: "ch-autocomplete-loading". -
highlightedClass
- String : Default: "ch-autocomplete-highlighted". -
itemClass
- String : Default: "ch-autocomplete-item". -
addClass
- String : CSS class names that will be added to the container on the widget initialization. Default: "ch-box-lite ch-autocomplete". -
keystrokesTime
- Number : Default: 150. -
html
- Boolean : Default: false. -
side
- String : The side option where the target element will be positioned. You must use: "left", "right", "top", "bottom" or "center". Default: "bottom". -
align
- String : The align options where the target element will be positioned. You must use: "left", "right", "top", "bottom" or "center". Default: "left". -
offsetX
- Number : The offsetX option specifies a distance to displace the target horitontally. -
offsetY
- Number : The offsetY option specifies a distance to displace the target vertically. -
positioned
- String : The positioned option specifies the type of positioning used. You must use: "absolute" or "fixed". Default: "absolute".
-
Extends
Properties
.$container
jQuerySelector | ZeptoSelector
The autocomplete container.
// Gets the autocomplete container.
autocomplete.$container;
.$trigger
jQuerySelector | ZeptoSelector
The autocomplete trigger.
.uid
Number
A unique id to identify the instance of a widget.
.Widget#name
String
The name of a widget.
// You can reach the instance associated.
var widget = $(selector).data(name);
Methods
-
event
- String : The name of the event you want to emit. -
var_args
- Object : Data to pass to the listeners. -
event
- String : The event name. -
event
- String : Event name. -
listener
- Function : Listener function. -
event
- String : The event name to subscribe. -
listener
- Function : Listener function. -
once
- Boolean : Indicate if a listener function will be called only one time. -
event
- String : Event name. -
listener
- Function : Listener function.
.constructor()
Returns a reference to the constructor function.
.destroy()
Destroys an Autocomplete instance.
// Destroying an instance of Autocomplete.
autocomplete.destroy();
.hide() → {autocomplete}
Hides widget's container.
// Hides an autocomplete.
autocomplete.hide();
.isShown() → {Boolean}
Returns a Boolean if the widget's core behavior is shown. That means it will return 'true' if the widget is on and it will return false otherwise.
// Execute a function if the widget is shown.
if (autocomplete.isShown()) {
fn();
}
.suggest() → {autocomplete}
Add suggestions to be shown.
.emit(event, var_args)
Execute each item in the listener collection in order with the specified data.
// Will emit the 'ready' event with 'param1' and 'param2' as arguments.
widget.emit('ready', 'param1', 'param2');
.getListeners(event) → {Array}
Returns all listeners from the collection for a specified event.
// Returns listeners from 'ready' event.
widget.getListeners('ready');
.off(event, listener) → {Object}
Removes a listener from the collection for a specified event.
// Will remove event listener to 'ready' event.
widget.off('ready', listener);
.on(event, listener, once)
Adds a listener to the collection for a specified event.
// Will add an event listener to 'ready' event.
widget.on('ready', listener);
.once(event, listener) → {Object}
Adds a listener to the collection for a specified event to will execute only once.
// Will add an event handler to 'contentLoad' event once.
widget.once('contentLoad', listener);
.constructor()
Returns a reference to the constructor function.
.destroy()
Destroys an instance of Widget and remove its data from asociated element.
// Destroying an instance of Widget.
widget.destroy();
.disable() → {instance}
Disables an instance of Widget.
// Disabling an instance of Widget.
widget.disable();
.enable() → {instance}
Enables an instance of Widget.
// Enabling an instance of Widget.
widget.enable();
.require() → {instance}
Adds functionality or abilities from other classes.
// You can require some abilitiest to use in your widget.
// For example you should require the collpasible abitliy.
var widget = new Widget(element, options);
widget.require('Collapsible');
Events
'destroy'
Emits when a widget is destroyed.
// Subscribe to "destroy" event.
widget.on('destroy', function () {
// Some code here!
});
'disable'
Emits when a widget is disable.
// Subscribe to "disable" event.
widget.on('disable', function () {
// Some code here!
});
'enable'
Emits when a widget is enable.
// Subscribe to "enable" event.
widget.on('enable', function () {
// Some code here!
});
'hide'
Event emitted when the Autocomplete container is hidden.
// Subscribe to "hide" event.
autocomplete.on('hide', function () {
// Some code here!
});
'ready'
Event emitted when the widget is ready to use.
// Subscribe to "ready" event.
autocomplete.on('ready',function () {
// Some code here!
});
'select'
Event emitted when a suggestion is selected.
// Subscribe to "select" event.
autocomplete.on('select', function () {
// Some code here!
});