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

Make sure tags that mismatch pattern are not added #23

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
20 changes: 17 additions & 3 deletions src/tags-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +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.indexOf(SEPERATOR) >= 0) {
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()) {
base.classList.add('error')
setTimeout( () => base.classList.remove('error') , 100)
return false;
}

// For duplicates, briefly highlight the existing tag
if (!input.getAttribute('duplicates')) {
Expand Down
5 changes: 5 additions & 0 deletions src/tags-input.less
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
border-radius: 2px;
box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);

&.error > input {
color: #FCC;
}

.tag {
display: inline-block;
background: #EEE;
Expand Down Expand Up @@ -44,6 +48,7 @@
font: inherit !important;
font-size: 100% !important;
outline: none !important;
transition: color 100ms ease;
}

.selected ~ input {
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