Skip to content

Commit ddf3833

Browse files
committed
feat: automatically add the check class
1 parent 4b10af9 commit ddf3833

File tree

5 files changed

+12
-9
lines changed

5 files changed

+12
-9
lines changed

dist/input-tags.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angularjs-input-tags",
3-
"version": "5.1.0",
3+
"version": "5.2.0",
44
"description": "AngularJS Component for input tags",
55
"author": {
66
"name": "Arthur Agombart",

src/input-tags.component.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class InputTags {
2121
this.tags = this.tags || [];
2222
this.suggestions = this.suggestions || {};
2323
this.displayProperty = this.displayProperty || 'text';
24-
this.keyProperty = this.keyProperty || '';
24+
this.keyProperty = this.keyProperty || this.displayProperty;
2525
this.placeholder = this.placeholder || 'Add a tag';
2626
this.spellcheck = this.spellcheck || true;
2727
this.maxLength = this.maxLength || MAX_SAFE_INTEGER;
@@ -31,7 +31,7 @@ class InputTags {
3131
}
3232

3333
track(tag) {
34-
return tag[this.keyProperty || this.displayProperty];
34+
return tag[this.keyProperty];
3535
}
3636

3737
getTagText(tag) {
@@ -40,7 +40,7 @@ class InputTags {
4040

4141
isTagValid(tag) {
4242
const tagText = this.getTagText(tag);
43-
const key = this.keyProperty || this.displayProperty;
43+
const key = this.keyProperty;
4444
return tagText &&
4545
this.tags.length <= this.maxLength &&
4646
!this.tags.some(element => element[key] === tag[key]);
@@ -53,7 +53,6 @@ class InputTags {
5353

5454
if (valid) {
5555
this.tags.push(tag);
56-
5756
this.emit('onTagAdded', {tag});
5857
} else {
5958
this.emit('onTagAddFailed', {tag});
@@ -62,6 +61,10 @@ class InputTags {
6261
return tag;
6362
}
6463

64+
isTagAdded(tag) {
65+
return this.tags.find(eTag => eTag[this.keyProperty] === tag[this.keyProperty]);
66+
}
67+
6568
removeTag(tag) {
6669
this.emit('onTagRemoving', {tag});
6770

src/input-tags.template.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</li>
1313
<li class="ait-dropdown-item"
1414
ng-class="{
15-
'ait-dropdown-item--checked': item.checked,
15+
'ait-dropdown-item--checked': $ctrl.isTagAdded(item),
1616
'ait-dropdown-item--last': !item.data || item.data.length === 0
1717
}"
1818
ng-repeat="item in $ctrl.currentItem.data track by item.code"
@@ -24,7 +24,7 @@
2424
ng-if="item.data && item.data.length > 0"></span>
2525
<span class="ait-dropdown-itemCheck"
2626
ng-class="$ctrl.itemCheckClass"
27-
ng-if="item.checked"></span>
27+
ng-if="$ctrl.isTagAdded(item)"></span>
2828
</li>
2929
</ul>
3030

0 commit comments

Comments
 (0)