[development] Forms API "Widgets", AJAX and non-JavaScript

Nedjo Rogers nedjo at islandnet.com
Wed Jan 31 04:45:58 UTC 2007


> I've done a couple of projects that needed custom "widgets" to use within 
> Forms API

A couple of ways I've seen this done are:

1. Add properties to your element and then, in a form_alter module, change 
the element accordingly. E.g. jscalendar.module in javascript tools, which 
attaches a 'jscalendar' class to specified textfields.

2. Define a custom #type, so that you will have full control over output 
(e.g., define your own theme function). This is initially attractive, but in 
the end a limited approach, since you lose the existing properties of a 
#type.

I suppose either way has its place. It gets tricky when we want to pass 
additional data along with a form element. This can be done in a few ways:

a. In an id or class (limited)
b. In a hidden form field (as with autocomplete)
c. Through a drupal_add_js() call of type 'setting'. For an example, see my 
Javascript patch to check/uncheck and enable/disable modules based on 
dependencies,  http://drupal.org/node/107038 (better yet, be the first to 
review it!) 



More information about the development mailing list