The module contains an important check for form errors, BUT this will never work because hook_form_alter is not called in such cases. See: https://www.drupal.org/node/671574

I had to debug a lot until I found that out...

I ended up this way...

/**
 * Implements hook_form_alter().
 *
 * Just add javascript to all forms.
 *
 * @param $form_id
 *    name of the form being acted on
 * @param $form
 *    array with form structure
 */
function saveguard_form_alter(&$form, &$form_state, $form_id) {
  $form['#after_build'][] = 'saveguard_form_alter_after_build';
}

/**
 * After build callback to run even if the form contains errors!
 */
function saveguard_form_alter_after_build($form, &$form_state) {
  $form['field']['#prefix'] = 'This text will rule them all!';
  drupal_add_js(drupal_get_path('module', 'saveguard') . '/saveguard.js');

  static $done;
  if (!$done) {
    $settings['saveguard'] = array(
      'msg' => variable_get('saveguard_message', NULL),
    );
    drupal_add_js($settings, array('type' => 'setting', 'scope' => 'header', 'group' => JS_DEFAULT));
    $done = TRUE;
  }

  return $form;
}

An that finally works :) :)

Comments

Anybody created an issue. See original summary.

Anybody’s picture

Priority: Normal » Major

Error functionality is broken completely so I'll correct the priority.

geek-merlin’s picture

Yes right. We should do something like this in hook_form_alter:

$form['#attach]['js'][] = $our_js;