I am having problems trying to get an autocomplete field populating with AJAX. One account user can have multiple members associated to it.
I have taken a step back by manually defining the array to get it working but something is still wrong. I assume it's something in my jQuery UI script as it's a big question mark for me at the moment.
The functionality I'm trying to create is that the user can start entering the name of a member (eg Smith, John) and selects it, the page will impersonate the user and reload the same page but appending the path with (in the example of Smith, John it would return ?_switch_user=jsmith)
HTML code:
<form class="navbar-form navbar-left" role="search">
<div class="form-group">
<input type="search" id="search-names" class="form-control" placeholder="Enter member name">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
jQuery UI script:
var UserArray = [
{ "label": "Smith, John", "value": "jsmith" },
{ "label": "Doe, Jane", "value": "jdoe1990" }
];
$( "#search-names" ).autocomplete({
source: UserArray,
minLength: 2,
change: function() {
var UserArray = $(this).val();
if (!UserArray) return;
window.location = window.location + '?_switch_user=' + UserArray.value
}
});
change()since it's the same as your array. 2) "label" and "value" should not be with quotes, but without them. see this fiddle: jsfiddle.net/Jorrex/wxh77suechange()was assigning the previousUserArray...(!)