Can I attach a jquery.ui.datepicker widget to a form element using the form api? I have a generic form element:

$form['date'] = array(
    '#type' =&gt; 'textfield',
    '#title' =&gt; t( 'Date' ),
);


That I want to add the jquery ui datepicker to this element. Is there a way to do this through the form api, or do I have to add the following using drupal_add_js:

$('#edit-date').datepicker();


Or is there another, even better way?
You can use after_build in your form to call a function that contains drupal_add_js