Autocomplete with the power of choice
I want to use autocomplete (jquery or .net) with a forced selection so that the user always selects something. There can be no login option, the user can choose.
Does anyone know how to do this?
I want to use webservice for this purpose because there will be a lot of results and I will show you the first few.
I want to display text in a hidden field after choosing to store the value
I want to use webservice for this purpose because there will be many results and I will show you the first few
a source to share
Doing this with a jQuery UI widget will require a little extra work on your part. I suggest you use the non-UI autocomplete plugin with the option mustMatch
. Note that if the user has JavaScript turned off, this does not guarantee that the input value will always be from your parameter set.
EDIT : Sample parser for autocomplete plugin. Expects an array of JSON objects of the form:
[ {
"FirstName" : "john",
"LastName" : "smith",
"Email" : "john-smith@example.com"
},
...
]
Setting up autocomplete
$('.selector').autocomplete({
...
parse: function(data) {
var array = new Array();
for(var i=0;i<data.length;i++)
{
var datum = data[i];
var name = datum.FirstName + ' ' + datum.LastName;
var display = name + ' (' + datum.Email + ')';
array[array.length] = { data: datum, value: display, result: name };
}
return array;
},
...
})
a source to share
You can use jQuery autocomplete as it supports force selection.
var availableTags = [
"ActionScript",
"AppleScript"
];
$("#tags").autocomplete({
source: availableTags,
change: function (event, ui) {
if(!ui.item){
//http://api.jqueryui.com/autocomplete/#event-change -
// The item selected from the menu, if any. Otherwise the property is null
//so clear the item for force selection
$("#tags").val("");
}
}
});
a source to share