From abff4ac1ab8d71c2b15865ef2bb04afcfadee410 Mon Sep 17 00:00:00 2001 From: Joakim Carlsson Kekonius Date: Fri, 24 May 2019 20:05:59 +0200 Subject: [PATCH] No value chips when empty string (#37) * WIP on changing empty text chips to text no value chips * Changed so translatable * changed to computed property noValueLabel --- paper-autocomplete-chips.html | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/paper-autocomplete-chips.html b/paper-autocomplete-chips.html index 2a0ba70..dbc749e 100644 --- a/paper-autocomplete-chips.html +++ b/paper-autocomplete-chips.html @@ -194,6 +194,11 @@ type: Boolean }, + noValueLabel: { + type: String, + computed: '_("No value", t)' + }, + /** * `` `queryFn` */ @@ -210,13 +215,13 @@ return; } return { - text: textValue.toString(), + text: textValue.toString() === '' ? this.noValueLabel : textValue.toString(), value: item }; } const objText = item.toString(); return { - text: objText, + text: objText === '' ? this.noValueLabel : objText, value: objText }; }, @@ -350,6 +355,7 @@ }; } + /** * Clear the selected items. * @param {object} event Polymer event object. @@ -373,10 +379,11 @@ * @returns {void} */ _getChipText(item, textProperty) { - if (typeof item === 'object') { - return this.get(textProperty, item) || item.text; + let localItem = item; + if (typeof text === 'object') { + localItem = this.get(textProperty, localItem) || localItem.text; } - return item; + return localItem !== '' ? localItem : this.noValueLabel; } /** * Update the selected items and request handle of suggestions.