From 4e3c7ecc9afdaeeeb9856e25caaa8b6402d81a72 Mon Sep 17 00:00:00 2001 From: Kasper Nilsson Date: Wed, 17 Aug 2016 11:50:29 -0700 Subject: [PATCH] Fix text undefined error This commit fixes the 'text is undefined' error in gr-autocomplete by setting a default value for text, as well as catching the case where text is set to undefined. This commit also disables the built-in autocomplete on the input element in the gr-autocomplete element to avoid redundancy. Bug: Issue 4276 Change-Id: Ia4d084068da223d10273110a402690e3b0af2e94 --- .../elements/shared/gr-autocomplete/gr-autocomplete.html | 3 ++- .../app/elements/shared/gr-autocomplete/gr-autocomplete.js | 3 ++- .../shared/gr-autocomplete/gr-autocomplete_test.html | 7 +++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/polygerrit-ui/app/elements/shared/gr-autocomplete/gr-autocomplete.html b/polygerrit-ui/app/elements/shared/gr-autocomplete/gr-autocomplete.html index 278f002e36..cda2492d0a 100644 --- a/polygerrit-ui/app/elements/shared/gr-autocomplete/gr-autocomplete.html +++ b/polygerrit-ui/app/elements/shared/gr-autocomplete/gr-autocomplete.html @@ -55,7 +55,8 @@ limitations under the License. bind-value="{{text}}" placeholder="[[placeholder]]" on-keydown="_handleInputKeydown" - on-focus="_updateSuggestions" /> + on-focus="_updateSuggestions" + autocomplete="off" />
diff --git a/polygerrit-ui/app/elements/shared/gr-autocomplete/gr-autocomplete.js b/polygerrit-ui/app/elements/shared/gr-autocomplete/gr-autocomplete.js index 871dbc1752..0fc6b0768d 100644 --- a/polygerrit-ui/app/elements/shared/gr-autocomplete/gr-autocomplete.js +++ b/polygerrit-ui/app/elements/shared/gr-autocomplete/gr-autocomplete.js @@ -64,6 +64,7 @@ text: { type: String, + value: '', observer: '_updateSuggestions', notify: true, }, @@ -131,7 +132,7 @@ }, _updateSuggestions: function() { - if (this._disableSuggestions) { return; } + if (!this.text || this._disableSuggestions) { return; } if (this.text.length < this.threshold) { this._suggestions = []; this.value = null; diff --git a/polygerrit-ui/app/elements/shared/gr-autocomplete/gr-autocomplete_test.html b/polygerrit-ui/app/elements/shared/gr-autocomplete/gr-autocomplete_test.html index 0ab9058fc5..f8b16b7b41 100644 --- a/polygerrit-ui/app/elements/shared/gr-autocomplete/gr-autocomplete_test.html +++ b/polygerrit-ui/app/elements/shared/gr-autocomplete/gr-autocomplete_test.html @@ -215,6 +215,13 @@ limitations under the License. assert.equal(element._computeClass(true), 'borderless'); }); + test('undefined or empty text results in no suggestions', function() { + sinon.spy(element, '_updateSuggestions'); + element.text = undefined; + assert(element._updateSuggestions.calledOnce); + assert.equal(element._suggestions.length, 0); + }); + test('multi completes only the last part of the query', function(done) { var promise; var queryStub = sinon.stub()