About

The Filter plugin introduces ability to limit input that the text field will accept. If the Tags plugin is used, Filter plugin will limit which tags it’s possible to add.

The list of allowed items can be either specified through the options, can come from the Suggestions plugin or be loaded by the Ajax plugin. All these plugins have one thing in common – they trigger setSuggestions event which the Filter plugin is expecting.

Examples

Options

Filter plugin options are grouped under filter when passed to the $().textext() function. For example:

$('textarea').textext({
    plugins: 'filter',
    filter: {
        items: [ "item1", "item2" ]
    }
})

filter.enabled (true)

This is a toggle switch to enable or disable the Filter plugin. The value is checked each time at the top level which allows you to toggle this setting on the fly.

filter.items (null)

Arra of items that the Filter plugin will allow the Tag plugin to add to the list of its resut tags. Each item by default is expected to be a string which default ItemManager can work with. You can change the item type by supplying custom ItemManager.

Events

Filter plugin dispatches and reacts to the following events.

isTagAllowed

Filter plugin reacts to the isTagAllowed event triggered by the Tags plugin before adding a new tag to the list. If the new tag is among the items specified in options, then the new tag will be allowed.

setSuggestions

Filter plugin reacts to the setSuggestions event triggered by other plugins like Suggestions and Ajax.

However, event if this event is handled and items are passed with it and stored, if items option was supplied, it will always take precedense.

Methods

TextExtFilter.init(core)

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

Initialization method called by the core during plugin instantiation.

TextExtFilter.isValueAllowed(value) 1.1

  • value {Object} Value to check.

Checks given value if it’s present in filterItems or was loaded for the Autocomplete or by the Suggestions plugins. value is compared to each item using ItemManager.compareItems method which is currently attached to the core. Returns true if value is known or Filter plugin is disabled.

TextExtFilter.onGetFormData(e, data, keyCode) 1.1

  • e {Object} jQuery event.

  • data {Object} Data object to be populated.

  • keyCode {Number} Key code that triggered the original update request.

Reacts to the getFormData event triggered by the core. Returns data with the weight of 200 to be greater than the Autocomplete plugins data weights. The weights system is covered in greater detail in the getFormData event documentation.

This method does nothing if Tags tag is also present.

TextExtFilter.onIsTagAllowed(e, data)

  • e {Object} jQuery event.

  • data {Object} Payload in the following format : { tag : {Object}, result : {Boolean} }.

Handles isTagAllowed event dispatched by the Tags plugin. If supplied tag is not in the items list, method sets result on the data argument to false.

TextExtFilter.onSetSuggestions(e, data)

  • e {Object} jQuery event.

  • data {Object} Payload in the following format : { result : {Array} } }.

Reacts to the setSuggestions events and stores supplied suggestions for future use.

Fork me on GitHub