Skip to content

Commit

Permalink
Inherit input's value on typeahead initialization.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake Harding committed Mar 12, 2013
1 parent 02311ea commit 1c11a94
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/input_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ var InputView = (function() {
40: 'down'
};

this.query = '';

this.$hint = $(o.hint);
this.$input = $(o.input)
.on('blur.tt', this._handleBlur)
Expand All @@ -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);
}
Expand Down
13 changes: 13 additions & 0 deletions test/input_view_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 1c11a94

Please sign in to comment.