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();