Skip to content

Instance methods

Rohit Vighne edited this page Aug 23, 2016 · 1 revision

These methods are available on any TagTrain instance and are the only recommended way to interface with the element.

Assume tagTrain is an instance of TagTrain created in the manner described here.

addTag

tagTrain.addTag(String value) -> Boolean

Attempts to add a new tag to the visible element and the internal tags array. If successful, returns true and triggers the add-tag event; otherwise, returns false. The following conditions may cause tag creation to fail (see options for details):

  • value is empty
  • The maximum number of tags is already filled
  • value is longer than the maximum allowed tag length
  • value fails the regular expression specified in the options
  • The given tag already exists

removeAll

tagTrain.removeAll() -> void

Removes all the tags from both the visible element and the internal tags array. Triggers the remove-all event.

getTags

tagTrain.getTags() -> Array[String]

Returns an array of the tags that have been inputted. This is a copy of the actual internal tags array, so modifying it is safe (does not have side-effects).

setTags

tagTrain.setTags(Array[String] tags) -> void

Removes all of the currently existing tags and adds in all the tags specified by tags. Triggers the remove-all and (repeatedly) add-tag events. Note that these tags are still subject to the validation rules explained in addTag.

takeFocus

tagTrain.takeFocus() -> void

Selects the contents of the tag input field.

Clone this wiki locally