From 2d238925d87225abeba4f8786897f9af36e81b19 Mon Sep 17 00:00:00 2001 From: Jake Harding Date: Fri, 7 Feb 2014 00:23:44 -0800 Subject: [PATCH] Have typeahead.val() mirror $.val(). Closes #659. --- src/typeahead/plugin.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/typeahead/plugin.js b/src/typeahead/plugin.js index 2397f747..09e9e83b 100644 --- a/src/typeahead/plugin.js +++ b/src/typeahead/plugin.js @@ -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; @@ -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();