diff --git a/src/input_view.js b/src/input_view.js index dea34feb..621df6c4 100644 --- a/src/input_view.js +++ b/src/input_view.js @@ -113,6 +113,10 @@ var InputView = (function() { return this.query; }, + setQuery: function(query) { + this.query = query; + }, + getInputValue: function() { return this.$input.val(); }, @@ -120,10 +124,7 @@ var InputView = (function() { setInputValue: function(value, silent) { this.$input.val(value); - // strict equal to support function(value) signature - if (silent !== true) { - this._compareQueryToInputValue(); - } + !silent && this._compareQueryToInputValue(); }, getHintValue: function() { diff --git a/src/typeahead.js b/src/typeahead.js index 6f686090..5b51ed1d 100644 --- a/src/typeahead.js +++ b/src/typeahead.js @@ -54,15 +54,26 @@ }, destroy: function() { - this.each(function() { - var $this = $(this), - view = $this.data(viewKey); + return this.each(destroy); + + function destroy() { + var $this = $(this), view = $this.data(viewKey); if (view) { view.destroy(); $this.removeData(viewKey); } - }); + } + }, + + setQuery: function(query) { + return this.each(setQuery); + + function setQuery() { + var view = $(this).data(viewKey); + + view && view.setQuery(query); + } } }; diff --git a/src/typeahead_view.js b/src/typeahead_view.js index f77147a3..0b76dc7c 100644 --- a/src/typeahead_view.js +++ b/src/typeahead_view.js @@ -272,6 +272,15 @@ var TypeaheadView = (function() { destroyDomStructure(this.$node); this.$node = null; + }, + + setQuery: function(query) { + this.inputView.setQuery(query); + this.inputView.setInputValue(query); + + this._clearHint(); + this._clearSuggestions(); + this._getSuggestions(); } });