I have used as a basis this question which works.
I have created a JsFiddle to try and find out why this is not working and for the life of me I cannot work it out. It will not find any results even though the result of say "H" is entered as the first letter of the lastName.
Can someone have a look and see why this is not pulling a match?
$(document).ready(function asdf() {
var users = [
{
id: "5",
userName: "Tclyde",
firstName: "Terry",
lasttName: "Adams",
},
{
id: "6",
userName: "LH",
firstName: "Leonie",
lasttName: "Henderson",
},
{
id: "7",
userName: "CharlesO",
firstName: "Charles",
lasttName: "O'Dwyer",
},
{
id: "2",
userName: "si2030",
firstName: "Simon",
lasttName: "O'Farrell",
},
{
id: "4",
userName: "blade44",
firstName: "Clyde",
lasttName: "Palmer",
},
{
id: "3",
userName: "tt2030",
firstName: "David",
lasttName: "Remmy",
}];
$("#search").autocomplete({
source: function (req, responseFn) {
var re = $.ui.autocomplete.escapeRegex(req.term);
var matcher = new RegExp("^" + re, "i");
var a = $.grep(users, function (item, index) {
return matcher.test(item.lastName);
});
a = $.map(a, function (x) {
return {
label: x.lastName + ", " + x.firstName,
value: x.id,
users: x
};
});
responseFn(a);
},
select: function (event, ui) {
location.href = "/UserAdmin/Edit/" + ui.item.id;
},
change: function (event, ui) {
if (!ui.item) {
$("#search").val("");
}
}
});
});