2

Showing a 'share' link in a textfield within a tooltip using qTip2.

The tooltip itself works fine, but I'd also like to get the textfield to have focus with all the text selected. Found this, but somehow the focus/click + select doesn't seem to be working.

JSFiddle link

Community
  • 1
  • 1
seekay
  • 2,493
  • 3
  • 27
  • 33

2 Answers2

3

Something seems to be removing the focus from the text input after the show callback is called; could just be a timing issue, could be something in qTip2 changing the focus.

You can try using a setTimeout with a time of zero to trigger a function once the browser gets control back (and that should happen after all the qTip2 stuff has finished). This works for me in Chrome, Safari, Firefox, and Opera:

events: {
    show: function(event, api) {
        var $this = $(this);
        setTimeout(function() {
            $this.find('input.focusselect').focus().select();
        }, 0);
    }
}

Demo: http://jsfiddle.net/ambiguous/npZgv/

mu is too short
  • 426,620
  • 70
  • 833
  • 800
1

In case any one is interested in another approach, here's the answer I got from Craig Thompson (qTip creator), which uses the autofocus event

           show: {
                event: 'click',
                ready: true,
                solo: true,
                autofocus: '.focusselect'
            },
            events: {
              show: function(event, api) {
                  $('input.focusselect', this).bind('focus', function() {
                      $(this).select();
                  });
              }
           }
seekay
  • 2,493
  • 3
  • 27
  • 33