Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add #280 suggestions, if group is set to
maxLength: 0
and global is…
… set to `maxLength: 1` Add `option.maxLength` to not search inside a group if above X characters Add group option to override the global config for `minLength`, `maxLength` and `dynamic` Add Deferred object for searching dynamic groups `this.node.triggerHandler('input').then(() => {})` Changed `dynamic` input event to `search` Fix issue when `maxItem` and `maxGroupItem` would send inaccurate results
- Loading branch information
1 parent
30a4e1f
commit 7ff0a45
Showing
15 changed files
with
507 additions
and
294 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const $ = require("jquery"); | ||
const Typeahead = require('../../src/jquery.typeahead'); | ||
|
||
describe('Typeahead onSendRequest Callback Tests', () => { | ||
'use strict'; | ||
|
||
let myTypeahead; | ||
|
||
beforeAll(() => { | ||
|
||
document.body.innerHTML = '<input class="js-typeahead">'; | ||
|
||
myTypeahead = $.typeahead({ | ||
input: '.js-typeahead', | ||
minLength: 0, | ||
generateOnLoad: true, | ||
display: ['name'], | ||
emptyTemplate: "no result for {{query}}", | ||
source: { | ||
group1: { | ||
ajax: { | ||
url: '' | ||
} | ||
}, | ||
group2: { | ||
ajax: { | ||
url: '' | ||
} | ||
} | ||
}, | ||
callback: { | ||
onSendRequest: function (node, event) { | ||
|
||
// Return false will prevent from sending Ajax request(s) | ||
return !!this.query.length; | ||
} | ||
} | ||
}); | ||
}); | ||
|
||
it('Should not display any data because the requests were canceled', () => { | ||
// @TODO Add the test | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
const $ = require("jquery"); | ||
const Typeahead = require('../../src/jquery.typeahead'); | ||
|
||
describe('Typeahead displays result according to input length per group', () => { | ||
|
||
let myTypeahead; | ||
|
||
beforeAll(() => { | ||
|
||
document.body.innerHTML = '<input class="js-typeahead">'; | ||
|
||
myTypeahead = $.typeahead({ | ||
input: '.js-typeahead', | ||
template: function () { | ||
return "{{display}}" | ||
}, | ||
source: { | ||
group1: { | ||
minLength: 0, | ||
maxLength: 2, | ||
data: [ | ||
'group1-data1', | ||
'group1-data2', | ||
'group1-data3' | ||
] | ||
}, | ||
group2: { | ||
minLength: 1, | ||
data: [ | ||
'group2-data1', | ||
'group2-data2', | ||
'group2-data3' | ||
] | ||
}, | ||
group3: { | ||
minLength: 0, | ||
data: [ | ||
'group3-data1', | ||
'group3-data2', | ||
'group3-data3' | ||
] | ||
}, | ||
group4: { | ||
maxLength: 3, | ||
data: [ | ||
'group4-data1', | ||
'group4-data2', | ||
'group4-data3' | ||
] | ||
}, | ||
group5: { | ||
minLength: 0, | ||
maxLength: 3, | ||
data: [ | ||
'group5-data1', | ||
'group5-data2', | ||
'group5-data3' | ||
] | ||
} | ||
} | ||
}); | ||
}); | ||
|
||
it('Should assign the proper Typeahead selector', () => { | ||
|
||
myTypeahead.node.val(''); | ||
myTypeahead.node.trigger('input'); | ||
|
||
expect(myTypeahead.searchGroups).toEqual(['group1', 'group3', 'group5']); | ||
|
||
myTypeahead.node.val('g'); | ||
myTypeahead.node.trigger('input'); | ||
|
||
expect(myTypeahead.searchGroups).toEqual(['group1', 'group2', 'group3', 'group5']); | ||
|
||
myTypeahead.node.val('gr'); | ||
myTypeahead.node.trigger('input'); | ||
|
||
expect(myTypeahead.searchGroups).toEqual(['group1', 'group2', 'group3', 'group4', 'group5']); | ||
|
||
myTypeahead.node.val('group'); | ||
myTypeahead.node.trigger('input'); | ||
|
||
expect(myTypeahead.searchGroups).toEqual(['group2', 'group3']); | ||
|
||
}); | ||
|
||
afterAll(() => { | ||
delete window.Typeahead['.js-typeahead']; | ||
}); | ||
|
||
}); |
Oops, something went wrong.