drupal_add_js + hook_form_alter
Interesting little gotcha I came across when working with the drupal form_api
When you want to add a js or css to a page, drupal_add_js and drupal_add_css is usually the best way to do it rather than outputting <script> tags. I needed to do as we use some js to manipulate the node edit forms.
But I found that if you use these functions are used in hook_form_alter the js/css files don’t get included on the page when a form has been validated. It will only appear on the first load. I don’t know why for sure but think it’s related form building/caching.
Anyway, a bit googling revealed that a way to make sure that js/css files are included all the time is to use $form[‘#after_build’]. More info on this drupal thread http://drupal.org/node/322290 and here http://switchbackcms.com/blog/right-way-include-javascript-your-drupal-form