Adding JS to a form within Omega 4 theme I need to add some JavaScript to forms within my Omega 4 theme.  My code right now is:

function mytheme_preprocess_form(&amp;$vars) {
    $vars['element']['#attached']['js'][] = 'path/to/myjs';
}


This isn't working, but it seems like it should.  I need to do this from my theme.  I don't want to use drupal_add_js(), since that's being deprecated.
You cannot do what you want to do in the form preprocessor.

Try using hook_form_alter() instead.

Keep reading for more information on why your current code doesn't work.

If you look at drupal_render() you can see that it runs this to theme the element:

if (isset($elements['#theme'])) {
  $elements['#children'] = theme($elements['#theme'], $elements);
}


This call to theme() is pretty much where your preprocess code code is running.

The output of that theme function (theme_form() outputs a string of form markup) is then going into $elements['#children'].

Then further down in drupal_render() it does this:

if (!empty($elements['#attached'])) {
  drupal_process_attached($elements);
}


But the #attached code you added never ended up back in the $elements of the drupal_render() function though so nothing happened.