Skip to content

Enable multiword search in contacts #97

Merged
merged 1 commit into from
Sep 16, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion mpicms/templates/personal/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,34 @@ <h1 class="title has-text-centered">{% trans 'Contact List' %}</h1>

var userList = new List('contacts', options);

function searchFunction(searchString, columns) {
var words = searchString.trim().split(/\s+/);
for (var item of userList.items) {
var values = item.values();
item.found = true;
for (var word of words) {
var word_found = false;
for (var column of columns) {
if (values.hasOwnProperty(column) && values[column] !== undefined && values[column] !== null) {
var text = (typeof values[column] !== 'string') ? values[column].toString() : values[column];
if (text.toLowerCase().indexOf(word) !== -1) {
word_found = true;
break;
}
}
}
if (word_found == false) {
item.found = false;
break;
}
}
}
}

var search_field = document.getElementById('search_field');
search_field.addEventListener('keyup', function() {
var searchString = search_field.value;
userList.search(searchString);
userList.search(searchString, ['first_name', 'last_name', 'email', 'phone'], searchFunction);
});

</script>