The following snippet is not working for me. Basically I want to check if there is an input element with the name "documents[]" and the value item.id and return void.
I thought this line would do it: $("input [name='documents[]'][value='"+item.id+"'") != false.
However the statement returns true every time. I have looked at the documentation for the jQuery constructor and it doesn't mention anything about returning false if no element is found for the selector.
How can I tell if the selector doesn't match any elements?
$.ajax({
url:'/myid/documents/json_get_documents/'+request.term,
dataType:"json",
success: function(data) {
response($.map(data, function(item){
if($("input [name='documents[]'][value='"+item.id+"'") != false) {
return; //This item has already been added, don't show in autocompete
}
return {
label: '<span class="file">'+item.title+'</span>',
id: item.id,
value: 'Search by title'
}
}))
}
});