I am curious if there is a way to get the modal form to capture the focus of the cursor. For instance, the login modal form should have the cursor in the username field by default. Is this easily done?

Members fund testing for the Drupal project. Drupal Association Learn more


scor’s picture

Title: Capture focus » Automatically set focus in login modal form username

yes, that would make a lot of sense. +1

selfsimilar’s picture

if you don't mind editing the module itself, you can add this behavior easily.

edit the file js/modal_forms_login.js:

(function ($) {

Drupal.behaviors.initModalFormsLogin = {
  attach: function (context, settings) {
    $("a[href*='/user/login'], a[href*='?q=user/login']", context).once('init-modal-forms-login', function () {
      this.href = this.href.replace(/user\/login/,'modal_forms/nojs/login');
    }).addClass('ctools-use-modal ctools-modal-modal-popup-small');

scor’s picture

@selfsimilar would you like to roll a patch? It seems like a good feature which should be part of this module.

selfsimilar’s picture

I'm happy to roll a patch for this. I just don't know if the patch would get rolled into the main branch. This was a quick little hack and if the main developer wanted this to be an optional change someone would have to add to the admin menu to etc.

That said, here's the patch.