bootstrap icon indicating copy to clipboard operation
bootstrap copied to clipboard

Focus on the first element with autofocus in a modal content once it's loaded and shown

Open lastnico opened this issue 13 years ago • 2 comments

Well, I guess the title is enough.

$(dialog.modalEl).find('input[autofocus]:first').focus();

(AngularStrap is doing the same)

lastnico avatar Apr 25 '13 07:04 lastnico

@lastnico are you talking about the custom $dialog where you can provide complete markup? If so I don't think it should be handled by the modal directive but rather it should be up to the markup. You are in complete control of the partial so you could put HTML5's autofocus attribute. Would it do the trick for you?

There is an ongoing discussion about the autofocus directive in AngularJS that could do 2-way data-binding so I think this would be a proper solution in the longer term.

Going to close for now but ready to be convinced :-)

pkozlowski-opensource avatar Apr 25 '13 19:04 pkozlowski-opensource

Yes, I am talking about this one, and the problem comes when a form is loaded dynamically (through a remote template for instance), because, of course, at this time, the autofocus attribute won't be taken into account, and, I guess, the only way to mimic this is to do it programmatically once it's displayed.

But you are right, I am aware about the current discussions on the focus/blur events on AngularJS. Let's see what will come from them.

lastnico avatar Apr 30 '13 07:04 lastnico