By bkosborne on
Hello all!
I'm writing some custom JS that needs to be added to the node form add/edit page for a specific content type. Looking thru what operations I could use for hook_nodeapi, I thought 'prepare' might work. However, it seems that it doesn't get invoked if a form validation error occurs.
I came across this stack overflow post regarding the issue, which suggests overriding the template function for the form and adding in my JS. Is that the best solution?
http://stackoverflow.com/questions/2584405/adding-js-to-a-drupal-node-form
Thank you
Brian
Comments
I might be being a bit thick,
I might be being a bit thick, but can't you just add the JS via hook_form_alter()?
I think the forms alters and
I think the forms alters and only called when the form is rebuilt - which doesn't happen in form validations and a few other instances i believe.
afterbuild function
Use hook_form_alter to add an afterbuild function. That will add the js even on validation errors.
Works for me, exactly what I
Works for me, exactly what I was looking for. Thank you!
Laurens Meurs
wiedes.nl
Great! It works on Drupal 7
Great! It works on Drupal 7 too.
Thank you.
Still works (D7)
My JS would add in hook_form_alter(), but stopped adding on validation. zbricoleur's solution worked for me. Thank you.