Add "Add to List" option for autocomplete
I'd like to have an "Add to list" option. Is there a best practice for this already, or do I need to invent it?
I'm already using the custom select option to fill in a hidden value, so I was thinking that it could also check for the selection of "Add to list" in the list and take action from there (pop up modal dialog with form, etc). The question is, should I have the server return this option in all results, or should I have javascript insert it after retrieving the data?
As suggested by one of the demos, I have:
- source: function(request, response) {
$.ajax({
url: "sourceurl",
dataType: "json",
data: {
term: request.term
},
success: function(data) {
response($.map(data, function(item) {
return {label: item.person.name
value: item.person.id}
}))
}
})
},
I think I'd like to just add another item to that response array, but my javascript knowledge is failing me now.