-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpaper-input-tags.html
81 lines (75 loc) · 1.96 KB
/
paper-input-tags.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../paper-input/paper-input.html">
<link rel="import" href="../paper-badge/paper-badge.html">
<link rel="import" href="tag-item.html">
<dom-module id="paper-input-tags">
<style>
tag-item{
margin-right:5px;
}
paper-badge{
display: inline-block;
position: inherit;
}
.tagscounter{
display: inline-block;
}
</style>
<template>
<paper-input-container id="input-tags">
<template is="dom-if" if="{{ label }}">
<label>[[label]]</label>
</template>
<template is="dom-repeat" items="{{ tags }}">
<tag-item styletag="{{ styletag }}" styleicon="{{ styleicon }}" value="{{ item }}" tags="{{ tags }}" index="{{ index }}"></tag-item>
</template>
<input is="iron-input" on-keydown="_keyDown">
</paper-input-container>
<template is="dom-if" if="{{ showtagcounter }}">
<div class="tagscounter">
<paper-badge class$="{{ stylecounter }}" label="{{ _tagsLength(tags) }}"></paper-badge>[[showtagcounter]]
</div>
</template>
</template>
</dom-module>
<script>
Polymer({
is: 'paper-input-tags',
properties: {
index: Number,
label: String,
showtagcounter: String,
stylecounter: String,
styleicon: String,
styletag: String,
tags: {
type: Array,
notify: true,
value: []
}
},
_addTag: function(tag) {
if (typeof(this.tags) == 'undefined') {
this.tags = [];
}
this.tags.push(tag);
this.tags = this.tags.slice();
},
_tagsLength: function(tags) {
return tags.length;
},
_getInputValue: function(inputvalue) {
return inputvalue.trim();
},
_keyDown: function(event) {
var keyVal = event.which;
if (keyVal === 13) {
var tag = this._getInputValue(event.target.value);
if ((tag !== '') && (this.tags.indexOf(tag) < 0)) {
this._addTag(tag);
event.target.value = '';
}
}
}
});
</script>