By: Spencer Neese
Version: 1.0
Requires: jQuery UI 1.7+ and jQuery 1.3.2+
Demo: http://jsfiddle.net/th3uiguy/MRu67/
Git: https://github.com/th3uiguy/jquery-listbuilder.git
jQuery List Builder uses the jQuery UI autocomplete to convert a basic input into an email client like "To" field with autocompletion.
(Boolean) Flag to show the 'X' icon on each list item.
(Boolean) When set to true, the user is only able to add items from the autocomplete source.
(Array) An array of items to be added when listBuilder is being initialized. Items may have a label, value or locked attribute.
- The
labelshould always be specified. - When
valueis not specified thelabelattribute is used instead. - The
lockedattribute will prevent a user from removing that element from the list and makes the list item appear like normal text in the field.
items: [
{"label": "Apples"},
{"label": "Pears", "value": 233},
{"label": "Oranges", "locked": true}
](Integer) The maximum number of items that the list should accept. When this limit is reached the onMaxReached function is called.
(Function) Triggered when the number of items entered is more than maxItems.
onMaxReached: function(item, $list){
alert(item.label + ' could not be added');
}
(Function) Places an add button to the right of the input and triggers this function when the add button is clicked.
onAddButtonClick: function(){
$('.listBuilder').listBuilder('add', {label:"Grapes"});
}
(Function) Triggered after an item is added to the list.
onAddItem: function(item){
alert(item.label + " was added");
}
(Function) Called before an item is added. This function should return true or false to the callback signifying if the item should be added or not.
beforeAddItem: function(item, callback){
var toAdd = (item.value !== 'peas');
callback(toAdd);
}
(Function) Triggered before an item is removed, from the list.
onRemoveItem: function(item, callback){
var toRemove = (item.value === 'peas');
callback(toRemove);
}
See http://jqueryui.com/demos/autocomplete/#options for a full description of these options.
Add an item to the list. Pass the new item as an object with label, value and locked.
$('input').listBuilder('add', {label:"Apples", value:"100", locked:false});
Get the current number of items in the list
$('input').listBuilder('count');
Copyright (c) 2012, Spencer Neese https://github.com/th3uiguy/
Dual licensed under the
MIT and
GPL Version 2 licenses.