diff --git a/module/tokenizer.js b/module/tokenizer.js index 4eb5755..9ced7ad 100644 --- a/module/tokenizer.js +++ b/module/tokenizer.js @@ -91,24 +91,35 @@ export class Tokenizer { // Get the value to add to the tokenizer let token = null + const value = this.input.value.trim() + let useInputValue = false + if (this._options.typeahead) { // If the typeahead option is set then look for the // `_token` value against the input. if (this.input._token) { + token = this.input._token delete this.input._token + + } else { + + // Check to see if the typeahead requires a match, if + // not then use the value of the current input. + useInputValue = !this.input._mhTypeahead.mustMatch } } else { // If not then check for a value in the input - const value = this.input.value.trim() + useInputValue = true + } - if (value !== '') { - token = { - 'label': value, - value - } + // If applicable set the token as the input value + if (useInputValue && value !== '') { + token = { + 'label': value, + value } } diff --git a/module/typeahead.js b/module/typeahead.js index 063c91a..6da71f7 100644 --- a/module/typeahead.js +++ b/module/typeahead.js @@ -235,6 +235,10 @@ export class Typeahead { return this._open } + get mustMatch() { + return this._options.mustMatch + } + get suggestionCount() { return this._suggestions.length } diff --git a/package.json b/package.json index c04f725..c09232f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "manhattan-typeahead", - "version": "1.0.8", + "version": "1.0.9", "description": "Type-a-head and tokens for form fields.", "engines": { "node": ">=8.9.4" diff --git a/spec/typeahead.spec.js b/spec/typeahead.spec.js index 8756093..d67d218 100644 --- a/spec/typeahead.spec.js +++ b/spec/typeahead.spec.js @@ -100,6 +100,12 @@ describe('Typeahead', () => { }) }) + describe('mustMatch', () => { + it('should return the must match flag for the typeahead', () => { + typeahead.mustMatch.should.be.false + }) + }) + describe('suggestionCount', () => { it('should return the number of suggestions for the current ' + 'query', async () => {