I am trying to use JQuery's blur with tag-it library, however, it isn't working.
I am not sure why blur isn't working.
I click off the input and nothing happens, I don't get an error.
The alert in the blur doesn't appear.
I have tried using:
.on(blur, handler)
And:
$(document).ready(function(){
("#id").blur()
})
Neither of them worked.
Here is my code:
var id_name = [[],[]];
var selected = true;
$("#Approversdisp").tagit({
allowSpaces: true,
autocomplete:{
minLength: 3,
delay: 600,
source: function(request, response){
$("#divreviewersearch").show();
$.ajax({
"url" :"private",
"type" : "GET",
"data" : {"name": request.term.trim()},
"contentType" : "application/json",
"success" : function(data) {
id_name[0] = data[0];
id_name[1] = data[1];
response(data[0]);
$("#divreviewersearch").hide();
},
"error" : function(error)
{
alert("error: "+JSON.stringify("There was an error!"));
}
});
},
select: function(event, ui) {
selected = false;
var nameid = ui.item.value;
var approvers = document.addcontent' . $item_id .'.Approvers.value;
ui.item.label = ui.item.label.replace(/\((.*?)\)/, "");
ui.item.value = ui.item.value.replace(/\((.*?)\)/, "");
document.addcontent' . $item_id .'.Approvers.value = approvers+"|"+id_name[1][id_name[0].indexOf(nameid)];
},
}
});
$("#Approversdisp").blur(function() {
alert("in blur");
if(selected){
var input = $("#Approversdisp").val();
input = input.split(",");
$("#Approversdisp").tagit("removeTagByLabel", input[input.length-1]);
alert("please pick the tag from the list.");
}
selected = true;
});
The expected result is the blur working.
I figured out the answer you have to use