Skip to content

Commit

Permalink
fixes #267
Browse files Browse the repository at this point in the history
  • Loading branch information
yairEO committed Dec 17, 2019
1 parent 89b98f5 commit 70d22dc
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
2 changes: 1 addition & 1 deletion dist/jQuery.tagify.min.js

Large diffs are not rendered by default.

15 changes: 10 additions & 5 deletions dist/tagify.js
Original file line number Diff line number Diff line change
Expand Up @@ -898,15 +898,20 @@ Tagify.prototype = {
if (this.settings.mode == 'select') this.DOM.scope.classList.toggle('tagify--invalid', isValid !== true);else this.DOM.input.classList.toggle('tagify__input--invalid', isValid !== true);
},
// remove any child DOM elements that aren't of type TEXT (like <br>)
normalize: function normalize() {
var node = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.DOM.input;
var clone = node,
normalize: function normalize(node) {
var clone = node || this.DOM.input,
//.cloneNode(true),
v = clone.innerText;
v = []; // when a text was pasted in FF, the "this.DOM.input" element will have <br> but no newline symbols (\n), and this will
// result in tags no being properly created if one wishes to create a separate tag per newline.

clone.childNodes.forEach(function (n) {
return n.nodeType == 3 && v.push(n.nodeValue);
});
v = v.join("\n");

try {
// "delimiters" might be of a non-regex value, where this will fail ("Tags With Properties" example in demo page):
v = v.replace(/(?:\r\n|\r|\n)/g, this.settings.delimiters.source.charAt(1));
v = v.replace(/(?:\r\n|\r|\n)/g, this.settings.delimiters.source.charAt(0));
} catch (err) {}

v = v.replace(/\s/g, ' ') // replace NBSPs with spaces characters
Expand Down
2 changes: 1 addition & 1 deletion dist/tagify.min.js

Large diffs are not rendered by default.

18 changes: 12 additions & 6 deletions src/tagify.js
Original file line number Diff line number Diff line change
Expand Up @@ -905,20 +905,26 @@ Tagify.prototype = {
},

// remove any child DOM elements that aren't of type TEXT (like <br>)
normalize( node = this.DOM.input ){
var clone = node, //.cloneNode(true),
v = clone.innerText;
normalize( node ){
var clone = node || this.DOM.input, //.cloneNode(true),
v = [];

// when a text was pasted in FF, the "this.DOM.input" element will have <br> but no newline symbols (\n), and this will
// result in tags no being properly created if one wishes to create a separate tag per newline.
clone.childNodes.forEach(n => n.nodeType==3 && v.push(n.nodeValue))
v = v.join("\n")

try{
// "delimiters" might be of a non-regex value, where this will fail ("Tags With Properties" example in demo page):
v = v.replace(/(?:\r\n|\r|\n)/g, this.settings.delimiters.source.charAt(1))
v = v.replace(/(?:\r\n|\r|\n)/g, this.settings.delimiters.source.charAt(0))
}
catch(err){}


v = v.replace(/\s/g, ' ') // replace NBSPs with spaces characters
.replace(/^\s+/, ""); // trimLeft
.replace(/^\s+/, "") // trimLeft

return v;
return v
},

/**
Expand Down
3 changes: 2 additions & 1 deletion test/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ <h3>Please select from the list:</h3>


var tagify3 = new Tagify(sectionElm.querySelector('input[name=value_JSON]'), {
delimiters: ",|[\\n\\r]"
delimiters: ",|[\\n\\r]",
addTagOnBlur: false
})

// should allow adding multiple tags as 1 string with new lines
Expand Down

0 comments on commit 70d22dc

Please sign in to comment.