Twitter's Bootstrap 2.x popover callback can't focus on element

Posted by mozgras on Stack Overflow See other posts from Stack Overflow or by mozgras
Published on 2013-07-01T01:45:51Z Indexed on 2013/07/01 23:05 UTC
Read the original article Hit count: 233

I've modified bootstrap's popover function to include a callback which works great. But in the callback I cannot programmatically focus on the first form field. Strange, because I can manipulate other elements in the callback function as well as focus on the element at other points.

Here's the code to add a callback which I got from another SO question (http://stackoverflow.com/a/14727204/1596547):

var tmp = $.fn.popover.Constructor.prototype.show;
$.fn.popover.Constructor.prototype.show = function () {
  tmp.call(this);
  if (this.options.callback) {
    this.options.callback();
  }
}

Here's the popover code:

$('#a-editor-btn').popover({
    html: true,     
    placement: 'bottom',
    callback: function(){
        $('#a-form-point').focus();  //nothing happens
        console.log('hello');  // works
    .
    .

    },
    content: $('#a-form').html()
}).parent().delegate('button#insert-point-btn', 'click', function() {
    insertPoint();
}).delegate('.a-form','keypress', function(e) {
    if ( e.which == 13 ) {
        insertPoint();
    }
});

© Stack Overflow or respective owner

Related posts about twitter-bootstrap

Related posts about callback