Skip to content

Commit

Permalink
Have typeahead.val() mirror $.val(). Closes #659.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake Harding committed Feb 9, 2014
1 parent 290fac4 commit 2d23892
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/typeahead/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@
},

val: function val(newVal) {
return _.isString(newVal) ?
this.each(setQuery) : this.map(getQuery).get();
// mirror jQuery#val functionality: reads opearte on first match,
// write operates on all matches
return !arguments.length ? getQuery(this.first()) : this.each(setQuery);

function setQuery() {
var $input = $(this), typeahead;
Expand All @@ -84,8 +85,8 @@
}
}

function getQuery() {
var $input = $(this), typeahead, query;
function getQuery($input) {
var typeahead, query;

if (typeahead = $input.data(typeaheadKey)) {
query = typeahead.getQuery();
Expand Down

0 comments on commit 2d23892

Please sign in to comment.