I had a similar need. I am using popover to display an in place edit form field. Once the value was saved, if you clicked the popover again the same source HTML was copied and the old value was selected. I played with setting the value on update and a few other things and nothing worked or I was not happy with the result.
I came up with this solution where instead of letting the show/hide events trigger I manually show and hide the popover.
$(document).on('click', '.ajax-value', function() {
// We only want to init the popover once
if (typeof $(this).data('bs.popover') == "undefined") {
// Init the popover and show immediately
$(this).popover({
'content': $(this).closest('.ajax-edit').find('.ajax-field').html(),
'html': true,
'title': $(this).attr('data-title'),
'placement': 'auto'
}).popover('show');
// Hook into show event and return false so parent does not run
$(this).on('show.bs.popover', function () {
return false;
});
// Same for hide, don't let parent execute
$(this).on('hide.bs.popover', function () {
return false;
});
} else {
// If we already created popover, just toggle hidden class
$(this).closest('.ajax-edit').find('.popover').toggleClass('hidden');
}
});
// This is a custom close button in the popover
$(document).on('click', '.ajax-field-close', function(){
// Just add the hidden class
$(this).closest('.ajax-edit').find('.popover').addClass('hidden');
});