I have something weird that is happening and I was hoping someone can shed some light on it for me. I am using the qtip2 plugin on an element on the page. Here is the code for it:
$('.tooltipEdit').click(function(){
var id = $(this).attr('id');
$(this).qtip({
show:{
event: 'click',
solo: true
},
content: {
text:'<form id="tooltipForm"><input type="text" value="'+$(this).text()+'" /> <button id="tooltipSave">Save</button></form>'
},
position : {
my : 'top center',
at: 'bottom center',
target: $('#'+id+'')
},
hide: {
delay : 500,
fixed: true
},
style: {
classes: 'ui-tooltip-blue ui-tooltip-shadow ui-tooltip-rounded'
},
events: {
show: function(event, api) {
$('#tooltipSave').click(function()
{
var contact = 0;
if($('#'+id+'').attr('id') == 'callFromContactName')
{
contact = $('#contactFromId').val();
}
if($('#'+id+'').attr('id') == 'callToContactName')
{
contact = $('#contactToId').val();
}
$.ajax(
{
type: "GET",
url: "php/myurl.php",
dataType: 'json',
data: 'callid='+$('#callid').val()+'&field='+$('#'+id+'').attr('id')+'&value='+encodeURIComponent($('#tooltipForm input').val())+'&contact='+contact,
success: function(j)
{
return true;
},
error: function()
{
return false;
}
});
return false;
});
}
}
});
As you can see I am creating a form within the tooltip with a "save button to submit back to the server.
I have seen two things that are strange.
1) When I click on the element with that class, the first click does nothing but then the second time I click on it the tooltip shows up. Why is it not coming up on the first click?
2) There are times when the wrong text is in showing inside the form within the tooltip. If I am using a dynamic population of the form, why would it not be the correct text all the time?
I have read about using jquery's destroy() method for pages with multiple tooltips and I bet that would help but I do not know where to use it.
All help would be appreciated!
UPDATE: You cna see the code in this jsFiddle: http://jsfiddle.net/DULDx/1/ Thanks!