Form Alter and #after_build
We have all faced situations in a drupal site where we have to insert js to controll form behaviours.
The common method that i had followed till now is to either
* Add a drupal_add_js in the form function or
* use a hook form alter to inset js using the same drupal_add_js
But if the the form fails validations then the js files are not included. This is because the Drupal caches the forms. And when there is a validation error it just pulls the forms from the cache.
I found my alternative here
Drupal forms have a parameter called #after_build
This is mainly used to alter fields after creating their displays.
But the callbacks given here will be trigerred even when the form is reproduced from cache!
That solved my problem..
You can find more details about #after_build here