How to add javascript after form was validated with ajax callback? I created a simple form.
How could I add JavaScript commands after form was validated? Why is it so hard do this?

$form['submit'] = array(
  '#type' =&gt; 'submit',
  '#value' =&gt; 'submit',
  '#validate' =&gt; 'my_validate_callback',
  '#ajax' =&gt; array(
    'callback' =&gt; 'my_form_callback',
    'method' =&gt; 'replace',
    'wrapper' =&gt; 'form-wrap',
    'effect' =&gt; 'fade'
  )
);
If you only want to add a JS file in validate or Ajax handler function you just need to add JS to form with drupal_add_js or attach it to form.

This is an example of how can you add JavaScript in Ajax callback function:

function my_form_callback(&amp;$form,$form_state){
if(some validation ){
$form['#attached']['js'] = array(
  drupal_get_path('module', 'ajax_example') . '/ajax_example.js',
);
}
return $form;
}