Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure tags must fit pattern before adding them #21

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tags-input",
"version": "1.1.1",
"version": "1.1.2",
"main": "tags-input.js",
"description": "<input type=\"tags\"> like magic.",
"scripts": {
Expand Down
19 changes: 15 additions & 4 deletions src/tags-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,26 @@ export default function tagsInput(input) {
// Return false if no need to add a tag
function addTag(text) {
// Add multiple tags if the user pastes in data with SEPERATOR already in it
if (~text.indexOf(SEPERATOR)) text = text.split(SEPERATOR);
if (Array.isArray(text)) return text.forEach(addTag);
if ( text.includes(SEPERATOR) ) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems a shame to give up IE compat here

text = text.split(SEPERATOR);
}
if ( Array.isArray(text) ) {
return text.forEach(addTag);
}

let tag = text && text.trim();
// Ignore if text is empty
if (!tag) return false;
if ( ! tag ) {
return false;
}

// Don't add if it's invalid (eg, for pattern=)
if ( ! base.input.checkValidity() ) {
return false;
}

// For duplicates, briefly highlight the existing tag
if (!input.getAttribute('duplicates')) {
if ( ! input.getAttribute('duplicates') ) {
let exisingTag = $(`[data-tag="${tag}"]`);
if (exisingTag) {
exisingTag.classList.add('dupe');
Expand Down
2 changes: 1 addition & 1 deletion tags-input.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tags-input.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tags-input.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading