Thickbox Login should have focus

momendo - June 18, 2007 - 15:40
Project:Thickbox
Version:6.x-1.2
Component:User interface
Category:feature request
Priority:normal
Assigned:jankoch
Status:needs review
Description

I tried the thickbox login feature. That's great but for usability, it should have auto focus on the first field (username). The user currently has to click on the field first. This will help save a click. It should be simple as to create a hook on the anchor?

#1

esadot - July 11, 2007 - 02:52

I second

#2

whatistocome - August 8, 2007 - 19:02

Definitely agree with this request - thickbox is really slick when used to display the login box, but visitors can get tripped up since they would need to know to click in the first (username) box.

~jason

#3

rbishop - October 2, 2007 - 19:40

Just add document.getElementById("edit-name").focus(); (with script tags wrapped around it) inside the form_alter. I added a type = markup field to the form and stuck that script in there.

#4

bendiy - October 2, 2007 - 22:15
Title:Thickbox Login should have focus» Can you elaborate

Can you elaborate on your post in the thickbox issues forum? I am interested in changing the focus to the username field, but I'm clueless as to what you said in your post. Where is form_alter and what is a type = markup field? Can you please post an example HTML form?

Thanks!

#5

bendiy - October 2, 2007 - 22:18
Title:Can you elaborate» Thickbox Login should have focus

-edit-

#6

frjo - October 3, 2007 - 10:41

In Firebug I can easily set focus to the field with this jQuery code:

$("#TB_window #edit-name")[0].focus();

My problem is to make in run when the popup opens.

rbishop could you paste in the exact code you are using in form_alter? I have tried different variations myself without success.

#7

rbishop - October 19, 2007 - 18:29

Seems to only work in Safari and breaks the thickbox for IE7
must be someway to focus the field this way

added this to the thickbox module in form_alter

    $form['login-forgot'] =  array('#type' => 'markup', '#value' => '<script>document.getElementById("edit-name").focus();</script><br/><br/><a href="javascript:;" onclick="forgotpass();">Forgot your password?</a>');

#8

mishakogan - November 24, 2007 - 22:54

Tried all of the above, and still cannot get it to work on firefox. PLEASE HELP!!!

#9

cronin - January 14, 2008 - 10:03

Any updates on this?

#10

drupalina - March 29, 2008 - 11:06

subscribing

#11

tadams303 - June 6, 2008 - 20:49

ditto

#12

frjo - June 7, 2008 - 08:16
Status:active» needs review

This solution is bit of a hack but it seems to work on my test site. Please try it out and report back here.

The patch adds this to the form_alter hook. The timeout makes is run after the 100 milliseconds, if it's not working for you try to increase it to 500 or something. (There are 1000 milliseconds in one second.)

$form['login-focus'] = array(
      '#type' => 'markup',
      '#value' => '<script type="text/javascript">$(document).ready(function() { setTimeout(\'$("#TB_window #edit-name")[0].focus();\', 100); });</script>'
    );

AttachmentSize
thickbox_login_focus_152712.patch 792 bytes

#13

christefano - June 25, 2008 - 00:04

Can the Focus module help in this situation?

#14

ekrispin - August 8, 2008 - 13:03

It doesn't work

#15

ekrispin - August 12, 2008 - 16:06

None of the suggestions above works, including the focus module.

#16

volkiz - August 18, 2008 - 13:31

this comment is about thickbox focus problem ( iframe mode ) not about drupal actually

i solved thickbox focus event problem like this:
i setted a function named "focus" that focus on "TB_iframeContent" , then textbox should be focused.
in this case i use a textbox with an id = "txtsearch"

in document ready function call this focus function with 100 ms delay
here is the code :
function focus(){
$("#TB_iframeContent").focus(); // here is the trick : first focus on iframe
$("#txtsearch").focus();
}

$(document).ready(function(){
setTimeout("focus();",100);
});

so i advice you to place this code on page will be open and dont forget include jquery.js

i hope this will be a solution for your drupal-thickbox problem.

#17

ekrispin - August 20, 2008 - 14:00

volkiz -

can you specify excatly where to put this code in the module?

Tnx.

#18

volkiz - August 20, 2008 - 22:49

as i said this is general thickbox problem
im not using thickbox for login in drupal
but maybe we can try this :
in thickbox module line 121 change thicbox_login function like this:

function thickbox_login() {

$output="function focus(){";
$output.='$("#TB_iframeContent").focus();';
$output.='$("#txtsearch").focus();';
$output.="}";

$output.="$(document).ready(function(){";
$output.='setTimeout("focus();",100);';
$output.="});";
print output;
print drupal_get_form('user_login');
exit;
}

tell me if its work

#19

ekrispin - August 23, 2008 - 12:20

Enclosed it in <script></script> and fixed the print line to be print $output; (the $ sign of the variable), even changed the field name but it doesn't work.

#20

volkiz - August 23, 2008 - 21:36

function thickbox_login() {
$output="function focus(){";
$output.='$("#TB_ajaxContent input[@id=edit-name]").hide();';
$output.="}";

$output.="$(document).ready(function(){";
$output.='setTimeout("focus();",100);';
$output.="});";
print $output;
print drupal_get_form('user_login');
exit;
}

check this login box will disappear onready state.
but if u change .hide(); to .focus(); id doesnt work.

besides drupal uses a modified version of thickbox (v3.0)
but i use this trick on thickbox (v2.1)
anyway its your turn ekrispin : )

#21

aruns4 - November 13, 2008 - 17:33

enabled thickbox module.

enabled for login in admin/settings/thickbox

changed the function code for login as u mentioned..

but login is still like the old one. it do not hide .

any ideas??

#22

jankoch - March 10, 2009 - 12:50
Version:5.x-1.0» 6.x-1.2
Assigned to:Anonymous» jankoch

#23

jankoch - March 10, 2009 - 13:32

I created a patch that adds focus the first form field of the modal ajax dialog of thickbox (which is used for the login) after 1000 ms (1 second). Also I added my recent bugfix of the translation problem of that modal ajax dialog to the patch.
For a *quick and dirty* manually fix add the following line to your thickbox.js on line 235:
window.setTimeout("document.forms[0].elements[0].focus()", 1000);

The snippet works perfectly for the thickbox-login, however it probably creates an error for modal ajax dialogs that do not contain any form elements. To address this issue I added a helper funtion that checks whether form[0].element[0] exists.

Use the thickbox_focus_only.patch iff you have already patched with my translation bugfix. (http://drupal.org/node/368080#comment-1332212)
Use thickbox_focus_and_translation_bugfix.patch instead to fix both, the issue that the modal dialog doesn't show correct translations as well as adding the focus feature.

AttachmentSize
thickbox_focus_and_translation_bugfix.patch 1.4 KB
thickbox_focus_only.patch 1.01 KB

#24

frjo - March 11, 2009 - 22:01
Status:needs review» fixed

Thanks for the patch jankoch, committed to 6-dev.

#25

xxvelcrar - March 24, 2009 - 02:06

To expand on jankoch's solution and make it a bit more robust, I replaced the first-form selection with a more target jQuery selector. Attached is a patch against the 6-dev snapshot. This fixed my problem with having a 'search' box on the same page as a popup login box.

AttachmentSize
thickbox_focus_jq.patch 344 bytes

#26

xxvelcrar - March 24, 2009 - 02:11
Status:fixed» needs review

#27

frjo - March 24, 2009 - 14:04

I have committed #26 from xxvelcrar to 6-dev so people can test it easily.

#28

zywiec - May 19, 2009 - 03:55

subscribing

#29

ekrispin - December 26, 2009 - 11:48

Both fixes #23 and #25 do not work. No focus whatsoever in neither IE, FF nor Chrome.

See here for example - click on the "Log In" link (at the top-right area).

 
 

Drupal is a registered trademark of Dries Buytaert.