Skip to content

Commit

Permalink
Add setQuery plugin method. Closes #28.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake Harding committed Mar 31, 2013
1 parent da624c5 commit 66baaf0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
9 changes: 5 additions & 4 deletions src/input_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,18 @@ var InputView = (function() {
return this.query;
},

setQuery: function(query) {
this.query = query;
},

getInputValue: function() {
return this.$input.val();
},

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() {
Expand Down
19 changes: 15 additions & 4 deletions src/typeahead.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
};

Expand Down
9 changes: 9 additions & 0 deletions src/typeahead_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});

Expand Down

0 comments on commit 66baaf0

Please sign in to comment.