Commit cdb6a11a authored by Andrei Vesterli's avatar Andrei Vesterli
Browse files

Issue #3066080 by el1_1el, andrei.vesterli: Validation handler of the next...

Issue #3066080 by el1_1el, andrei.vesterli: Validation handler of the next button breaks other form validation
parent 267f2a2c
Loading
Loading
Loading
Loading
+37 −0
Original line number Diff line number Diff line
@@ -28,6 +28,9 @@ function simple_multistep_form_alter(&$form, FormStateInterface &$form_state) {

    // Attach style library.
    $form['#attached']['library'][] = 'simple_multistep/simple_multistep';

    // Add validation handler.
    $form['#validate'] = array_merge(['simple_multistep_multistep_validate'], $form['#validate']);
  }
}

@@ -132,3 +135,37 @@ function _check_form_multistep(array $form) {

  return FALSE;
}

/**
 * Image and File element widgets need resetting
 * after multistep Next submits.
 */
function _simple_multistep_fix_widget_elements($element) {
  if (isset($element[1])) {
    $keys = array_keys($element);
    foreach ($keys as $key) {
      if ($key > 0 && empty($element[$key-1]['#default_value']['fids'])) {
        unset($element[$key]);
      }
    }
    if (!isset($element[1])) {
      $element['#file_upload_delta'] = 0;
    }
  }

  return $element;
}

/**
 * Implements hook_field_widget_WIDGET_TYPE_form_alter().
 */
function simple_multistep_field_widget_file_generic_form_alter(&$element, FormStateInterface $form_state, $context) {
  $element = _simple_multistep_fix_widget_elements($element);
}

/**
 * Implements hook_field_widget_WIDGET_TYPE_form_alter().
 */
function simple_multistep_field_widget_image_image_form_alter(&$element, FormStateInterface $form_state, $context) {
  $element = _simple_multistep_fix_widget_elements($element);
}
+2 −2
Original line number Diff line number Diff line
@@ -63,8 +63,8 @@ class FormButton extends FormStep {
      $form['actions']['next'] = [
        '#type' => 'button',
        '#value' => $step_format_settings['next_button_text'],
        '#validate' => ['simple_multistep_register_next_step'],
        '#submit' => [],
        '#submit' => ['simple_multistep_register_next_step'],
        '#executes_submit_callback' => TRUE,
        '#weight' => 0.1,
      ];
      $form['actions']['submit']['#access'] = FALSE;