Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inherit input's value on typeahead initialization #109

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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