Skip to content

JavaScript Tags

The jSuites.tags is a lightweight JavaScript Tags and Keywords input component for web applications. This plugin streamlines the inputting and organizing of numerous tags or keywords within a text input field. Its adaptability renders it an invaluable resource for a wide array of uses, such as:

  • Input boxes for keywords, tags, and categories
  • Input validations
  • Destination email fields
  • CRM and CMS systems
  • SEO systems for managing tags and keywords

The following methods are provided to facilitate the integration of the component with web applications:

MethodDescription
getData();Get all tags as a object
getValue(number)Get a specific tag by index or all tags value
@param integer indexNumber - Null for all tags
setValue(string);Set a new value for the javascript tagging
@param string newValue - Values separate by comma
reset();Clear all tags
isValid();Validate tags

These events allow for customized behaviour adjustments of the component:

MethodDescription
onbeforechangeMethod executed before a value is changed.
(HTMLElement element, Object instance, String value) => string
onbeforepasteMethod executed before the paste data is appended.
(HTMLElement element, Object instance, Array data) => string
onchangeMethod executed when a value is changed.
(HTMLElement element, Object instance, String value) => void
onfocusMethod executed when the input is focused.
(HTMLElement element, Object instance, String currentValue) => void
onblurMethod executed when the input is focused.
(HTMLElement element, Object instance, String currentValue) => void
onloadMethod executed the DOM element is ready.
(HTMLElement element, Object instance) => void
onremoveitemMethod executed when a item is removed.
(String title, HTMLElement removedElement) => void

To initialize a new tag or keyword input element, configure the following settings:

PropertyDescription
value: string | arrayInitial value of the component. A string separated by comma or an array of objects.
limit: numberMax number of tags inside the element
search: stringThe URL for the remote suggestions
placeholder: stringThe default instruction text on the element
validation: functionMethod to validate the entries in the input.
(HTMLElement element, String value, Number id) => boolean

Implement an essential keywords management input using the jSuites.tags as a JavaScript web component. This setup allows for efficient handling and organization of keywords within a user-friendly input field, suitable for various applications such as content tagging, search engine optimization tools, and metadata management.

<html>
<script src="https://jsuites.net/v6/jsuites.js"></script>
<script src="https://jsuites.net/v6/jsuites.webcomponents.js"></script>
<link rel="stylesheet" href="https://jsuites.net/v6/jsuites.css" type="text/css" />

<jsuites-tags value="Canada,US,UK"></jsuites-tags>

<script>
document.querySelector('jsuites-tags').addEventListener('onblur', function() {
    console.log(this.textContent);
});
</script>
</html>

A basic javascript tags input component.

<html>
<script src="https://jsuites.net/v6/jsuites.js"></script>
<script src="https://jsuites.net/v6/jsuites.webcomponents.js"></script>
<link rel="stylesheet" href="https://jsuites.net/v6/jsuites.css" type="text/css" />

<div id='tag-input1' style="width: 320px"></div>

<script>
jSuites.tags(document.getElementById('tag-input1'), {
    value: 'Canada,US,UK',
    onblur: function() {
        console.log(arguments)
    }
});
</script>
</html>

Set up a Gmail-like email input using jSuites.tags that support validations and remote suggestions optimized for keyboard interactions.

<html>
<script src="https://jsuites.net/v6/jsuites.js"></script>
<script src="https://jsuites.net/v6/jsuites.webcomponents.js"></script>
<link rel="stylesheet" href="https://jsuites.net/v6/jsuites.css" type="text/css" />

<div id='tag-input2' style="width: 320px"></div>

<script>
jSuites.tags(document.getElementById('tag-input2'), {
    validation: function(element, text, value) {
        if (! value) {
            value = text;
        }
        var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
        var test = re.test(String(value).toLowerCase()) ? true : false;
        return test;
    },
    search: '/docs/data?q=',
    placeholder: 'To'
});
</script>
</html>