About

ItemManager is used to seamlessly convert between string that come from the user input to whatever the format the item data is being passed around in. It’s used by all plugins that in one way or another operate with items, such as Tags, Filter, Autocomplete and Suggestions. Default implementation works with String type.

Each instance of TextExt creates a new instance of default implementation of ItemManager unless itemManager option was set to another implementation.

To satisfy requirements of managing items of type other than a String, different implementation if ItemManager should be supplied.

If you wish to bring your own implementation, you need to create a new class and implement all the methods that ItemManager has. After, you need to supply your pass via the itemManager option during initialization like so:

$('#input').textext({
    itemManager : CustomItemManager
})

Methods

ItemManager.compareItems(item1, item2)

  • item1 {Object} First item.

  • item2 {Object} Second item.

Returns true if both items are equal, false otherwise. Because default implemenation works with string, input items are compared as strings. To use custom objects, different implementation of this method could for example compare name fields of { name : {String} } type object.

ItemManager.filter(list, query)

  • list {Array} List of items. Default implementation works with strings.

  • query {String} Query string.

Filters out items from the list that don’t match the query and returns remaining items. Default implementation checks if the item starts with the query.

ItemManager.init(core)

  • core {TextExt} Instance of the TextExt core class.

Initialization method called by the core during instantiation.

ItemManager.itemContains(item, needle)

  • item {Object} Item to check. Default implementation works with strings.

  • needle {String} Search string to be found within the item.

Returns true if specified item contains another string, false otherwise. In the default implementation String.indexOf() is used to check if item string begins with the needle string.

ItemManager.itemToString(item)

  • item {Object} Input item to be converted to string.

Converts specified item to string. Because default implemenation works with string, input string is simply returned back. To use custom objects, different implementation of this method could for example return name field of { name : {String} }.

ItemManager.stringToItem(str)

  • str {String} Input string.

Converts specified string to item. Because default implemenation works with string, input string is simply returned back. To use custom objects, different implementation of this method could return something like { name : {String} }.

Fork me on GitHub