I'd love to be able to focus on a textarea if that's the first element in my form.

I peeked in the code and see it is only looking for 'input'.

        $jquery_snippet = '$(document).ready(function(){$("#'. $form['#id'] . ' input").not("[@type=\'hidden\']")[0].focus()});'; 

Now, what a great time for me to start learning more about jquery, but I thought I'd throw this out there in case you can do it in your sleep.

Comments

calebtr’s picture

I thought about this some more, and I realized the jQuery snippet is looking for the first item in an array of inputs, so a textarea wouldn't be included.

Instead of having jQuery figure out which field to focus on, why not have Drupal pick the field by seeing which textarea or input comes first? I poked around and saw that drupal uses this code to sort forms drupal_render:

  if (!isset($form['#sorted'])) {
    uasort($form, "_element_sort");
  }

I toyed around but wasn't able to add a quick fix.

anders.fajerson’s picture

Version: 5.x-1.0 » 6.x-1.x-dev
Status: Active » Fixed
calebtr’s picture

Works great - thanks!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.