From 1c11a942b017276c4916ccbd33b2e06b6c1f715e Mon Sep 17 00:00:00 2001 From: Jake Harding Date: Mon, 11 Mar 2013 20:45:17 -0700 Subject: [PATCH] Inherit input's value on typeahead initialization. --- src/input_view.js | 6 ++++-- test/input_view_spec.js | 13 +++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/input_view.js b/src/input_view.js index 955e689b..10cdcdcf 100644 --- a/src/input_view.js +++ b/src/input_view.js @@ -24,8 +24,6 @@ var InputView = (function() { 40: 'down' }; - this.query = ''; - this.$hint = $(o.hint); this.$input = $(o.input) .on('blur.tt', this._handleBlur) @@ -51,6 +49,10 @@ var InputView = (function() { }); } + // the query defaults to whatever the value of the input is + // on initialization, it'll most likely be an empty string + this.query = this.$input.val(); + // helps with calculating the width of the input's value this.$overflowHelper = buildOverflowHelper(this.$input); } diff --git a/test/input_view_spec.js b/test/input_view_spec.js index c43490b7..6de6ce42 100644 --- a/test/input_view_spec.js +++ b/test/input_view_spec.js @@ -149,6 +149,19 @@ describe('InputView', function() { // public methods // -------------- + describe('#constructor', function() { + beforeEach(function() { + this.inputView.destroy(); + + this.$input.val('hey there'); + this.inputView = new InputView({ input: this.$input, hint: this.$hint }); + }); + + it('should default the query to the value of the input', function() { + expect(this.inputView.getQuery()).toBe('hey there'); + }); + }); + describe('#destroy', function() { beforeEach(function() { this.inputView.destroy();