1

I'm using impromptu

http://www.shiguenori.com/material/jquery.impromptu/

to show dialog boxes and collect user's input.

But I can't get the input textbox to focus when it appears.

I've tried giving the input an id and add in impromptu.js

$('#impromptu_fname').focus();

in several placess.

I also tried adding autofocus to the input.

None of that worked. Any ideas?

madprops
  • 3,909
  • 5
  • 34
  • 42

2 Answers2

2

You'll have to do it in the loaded callback:

$.prompt('Your message goes here.', {
    // options
    loaded: function(){
        $('#impromptu_fname').focus();
    }
});
Joseph Silber
  • 214,931
  • 59
  • 362
  • 292
  • I should also add that some versions of impromptu focus the buttons after they call the loaded callback. In these versions, setting the focus property on the prompt to an invalid high number will work. – techdude Mar 17 '17 at 18:45
1

Thanks for the tip to use the loaded callback. I had the same problem, however to get the focus on the default button of the initial prompt, here's how I did it:

var myPrompt = $.prompt(tourStates);
myPrompt.on('impromptu:loaded', function(e){$('button.jqidefaultbutton[id^="jqi_0"]').focus();});
Dmargster
  • 21
  • 3