Skip to content
This repository has been archived by the owner on Apr 28, 2020. It is now read-only.

Commit

Permalink
added searchColumns option
Browse files Browse the repository at this point in the history
  • Loading branch information
vdepizzol committed May 10, 2011
1 parent 4ee6cdb commit bdff27e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
5 changes: 3 additions & 2 deletions demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ <h2 id="allowcustomentry">Allowing Custom Entry</h2>
</script>
</div>

<h2 id="parsename">Using local data with parseName function</h2>
<h2 id="parsename">Using local data with parseName function and searchColumns setting</h2>
<div>
<input type="text" id="demo-input-parsename" name="blah" />
<input type="button" value="Submit" />
Expand All @@ -245,7 +245,8 @@ <h2 id="parsename">Using local data with parseName function</h2>
{
parseName: function(element) {
return element.name + ', '+ element.state;
}
},
searchColumns: ['name', 'state']
});
});
</script>
Expand Down
13 changes: 8 additions & 5 deletions src/jquery.tokeninput.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var DEFAULT_SETTINGS = {
prePopulate: null,
processPrePopulate: false,
parseName: null,
searchColumns: ['name'],
animateDropdown: true,
onResult: null,
onAdd: null,
Expand Down Expand Up @@ -822,11 +823,13 @@ $.TokenList = function (input, url_or_data, settings) {
} else if(settings.local_data) {
// Do the search through local data
var results = $.grep(settings.local_data, function (row) {
if(row.name.toLowerCase().removeDiacritics().indexOf(query.toLowerCase().removeDiacritics()) > -1) {
return true;
} else {
return false;
}
var founded = false;
$(settings.searchColumns).each(function(i, item) {
if(row[item].toString().toLowerCase().removeDiacritics().indexOf(query.toString().toLowerCase().removeDiacritics()) > -1) {
founded = true;
}
});
return founded;
});

if($.isFunction(settings.onResult)) {
Expand Down

0 comments on commit bdff27e

Please sign in to comment.