This patch allows onfocus and onblur events to be added to textfields through the interface.

Kudos to the overall design of this system. This functionality was really easy to add. Thanks.

I didnt look into other use-cases but other people might want to add onfocus and onblur events to other components.

Also I didnt really know where to set the weight so i just choose something.

Please review and comment.

Comments

quicksketch’s picture

This has been marked won't fix once before. See #280408: onchange javascript injection for text fields.

Syph’s picture

I use this all the time for text fields but I am having trouble trying to add this to select boxes?

Can someone point me in the right direction.

Jackinloadup’s picture

@Syph
usually for select boxes you want onchange

quicksketch’s picture

Status: Needs review » Closed (won't fix)
twram’s picture

How do you add a the patch to the webform module?

picciuto’s picture

Read this on applying patches. http://drupal.org/patch/apply

tustind’s picture

To make this work for versions 6.x-3.4, copy the code below at line 117 of the component/textfield.inc:

   $form['extra']['attributes']['onfocus'] = array(
     '#type' => 'textfield',
     '#title' => 'Onfocus',
     '#description' => t('Javascript code placed in the onfocus input attribute.'),
     '#default_value' => $component['extra']['attributes']['onfocus'],
     '#size' => 20,
     '#weight' => 4,
   );
   $form['extra']['attributes']['onblur'] = array(
     '#type' => 'textfield',
     '#title' => 'Onblur',
     '#description' => t('Javascript code placed in the onblur input attribute.'),
     '#default_value' => $component['extra']['attributes']['onblur'],
     '#size' => 20,
     '#weight' => 4.1,
   );  
  return $form;
}
shadowdknight’s picture

How does it work in 7.x-3.x?

Thanks!