Skip to content

Commit

Permalink
if search field is empty, all items should match. orchidjs/tom-select#78
Browse files Browse the repository at this point in the history
  • Loading branch information
oyejorge committed May 10, 2021
1 parent eca2800 commit 19a3f63
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/sifter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ export default class Sifter{
field_count = fields.length,
getAttrFn = search.getAttrFn;

if (!field_count) {
return function() { return 1; };
}


/**
Expand All @@ -161,9 +164,6 @@ export default class Sifter{
*/
const scoreObject = (function() {

if (!field_count) {
return function() { return 0; };
}

if (field_count === 1) {
return function(token:TToken, data) {
Expand Down
17 changes: 17 additions & 0 deletions test/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,4 +287,21 @@ describe('#search()', function() {
});


it('empty field', function() {

var data = [
{fieldx: 'aaa', fieldy: 'abb'},
{fieldx: 'abb', fieldy: 'aaa'}
];
var sifter = new Sifter(data);

var result = sifter.search('b', {
fields: []
});

assert.equal(result.items.length,2);
assert.equal(result.items[0].id,0);
});


});

0 comments on commit 19a3f63

Please sign in to comment.