jQuery .focus() on modal add page

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
sangnandar
User
Posts: 980

jQuery .focus() on modal add page

Post by sangnandar »

I need help here.

My setup:
Add page with modal enabled.
#x_myField is TEXT.

By default when the modal shown it set focus on Add button.
I need change this focus to #x_myField.

Startup Script:
$(document).ready(function() {
$("#ewModalDialog").on("shown.bs.modal", function() {
$("#x_myField").focus();
});
});

But it still focus on Add button.


mobhar
User
Posts: 11660

Post by mobhar »

It seems you have already asked this question a few days ago, and you found the answer for yourself, too. See your post here: http://www.hkvforums.com/viewtopic.php?f=4&t=39214


arbei
User
Posts: 9288

Post by arbei »

Just add your code to set focus in Startup Script of the add page is fine.

For example:
$("x_<Fiend>").focus();


sangnandar
User
Posts: 980

Post by sangnandar »

mobhar wrote:
It seems you have already asked this question a few days ago, and you found
the answer for yourself, too. See your post here:
http://www.hkvforums.com/viewtopic.php?f=4&t=39214

It was for #ewModalLookupDialog and it works fine there. But please also note that in the latest template the code
.find(".form-control:first").focus(); // this is lookup dialog search-box
is no longer needed since #ewModalLookupDialog already set the search-box as the default focus.


sangnandar
User
Posts: 980

Post by sangnandar »

arbei wrote:
Just add your code to set focus in Startup Script of the add page is fine.

For example:
$("x_<Fiend>").focus();

Geez...thanks, it works. Didn't think of that before.
And just to be safe I add #ewModalDialog into the selector.
$("#ewModalDialog #x_<field>").focus();


Post Reply