Skip to content

Commit 3440c32

Browse files
Merge pull request #25 from fabito/add/filter-inactive-attribute
Ability to exclude "inactive" items from suggestion
2 parents c19183e + ec89fb3 commit 3440c32

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

demo/index.html

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,15 @@ <h1>[email protected]</h1>
159159
<iron-icon icon="visibility" suffix></iron-icon>-->
160160
</paper-input-autocomplete-chips>
161161
</paper-material>
162+
163+
164+
<paper-material class="demo-paper" style="height: 300px; overflow: auto;">
165+
<p>An example of <code>&lt;paper-input-autocomplete-chips&gt;</code> with the <code>noSuggestInactive</code> attribute:</p>
166+
<p>It won't suggest neither Alabama nor Alaska</p>
167+
<paper-input-autocomplete-chips local-candidates="{{states}}" label="Chips" no-suggest-inactive>
168+
</paper-input-autocomplete-chips>
169+
</paper-material>
170+
162171

163172
<script>
164173
window.addEventListener('WebComponentsReady', function() {
@@ -257,12 +266,14 @@ <h1>[email protected]</h1>
257266
text: "Alabama",
258267
imgUrl: 'https://lh5.googleusercontent.com/-tlQ1LE9IdgI/AAAAAAAAAAI/AAAAAAAAAAA/xTWfNFP8w_M/s32-c-mo/photo.jpg',
259268
tag: 'read-only',
260-
readOnly: false
269+
readOnly: false,
270+
inactive: true
261271
},
262272
{
263273
key: 2,
264274
text: "Alaska",
265-
imgUrl: 'http://lorempixel.com/256/256/'
275+
imgUrl: 'http://lorempixel.com/256/256/',
276+
inactive: true
266277
},
267278
{
268279
key: 3,

input-autocomplete-behavior.html

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,16 @@
123123
type: Boolean,
124124
value: false
125125
},
126+
127+
/**
128+
* If set to true, candidate items which property 'inactive' are set to true
129+
* won't be suggested
130+
*/
131+
noSuggestInactive: {
132+
type: Boolean,
133+
value: false
134+
},
135+
126136
},
127137

128138
_tokenAcceptKeyCodesChanged: function (newValue) {
@@ -475,11 +485,15 @@
475485

476486
var patt = new RegExp( this._scapeString( term.toLowerCase() ) );
477487
var matched = [];
478-
479-
if ( this.localCandidates && this.localCandidates.length ){
480-
for (var i = 0; i < this.localCandidates.length; i ++){
481-
if (patt.test(this.localCandidates[i].text.toLowerCase()) == true){
482-
matched.push(this.localCandidates[i]);
488+
var candidates = this.localCandidates;
489+
490+
if (candidates && candidates.length) {
491+
for (var i = 0; i < candidates.length; i ++) {
492+
var candidate = candidates[i];
493+
if (Boolean(this.noSuggestInactive) && !Boolean(candidate.inactive)) {
494+
if (patt.test(candidate.text.toLowerCase()) == true){
495+
matched.push(candidate);
496+
}
483497
}
484498
}
485499
}

0 commit comments

Comments
 (0)