Skip to content

Commit

Permalink
Added support for typeahead+tokenizer+free-entry
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyjb committed Jul 18, 2018
1 parent 1cb2554 commit 04aac74
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
23 changes: 17 additions & 6 deletions module/tokenizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
4 changes: 4 additions & 0 deletions module/typeahead.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ export class Typeahead {
return this._open
}

get mustMatch() {
return this._options.mustMatch
}

get suggestionCount() {
return this._suggestions.length
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
6 changes: 6 additions & 0 deletions spec/typeahead.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit 04aac74

Please sign in to comment.