Skip to content

Instantly share code, notes, and snippets.

@nalipaz
Created September 18, 2014 20:29
Show Gist options
  • Save nalipaz/09ae34b323e9ee1c6f43 to your computer and use it in GitHub Desktop.
Save nalipaz/09ae34b323e9ee1c6f43 to your computer and use it in GitHub Desktop.
Drupal: How to correctly add js in a form_alter()
<?php
function MODULE_NAME_form_alter($form, &$form_state, $form_id) {
...
$form['#after_build'] = array('MODULE_NAME_add_assets');
...
}
function MODULE_NAME_add_assets($element) {
drupal_add_js(......);
return $element;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment