You are here

public function ConditionalFieldsFormHelper::addValidationCallback in Conditional Fields 4.x

Same name and namespace in other branches
  1. 8 src/ConditionalFieldsFormHelper.php \Drupal\conditional_fields\ConditionalFieldsFormHelper::addValidationCallback()

Add validation callback to manage dependent fields validation.

File

src/ConditionalFieldsFormHelper.php, line 206

Class

ConditionalFieldsFormHelper
Helper to interact with forms.

Namespace

Drupal\conditional_fields

Code

public function addValidationCallback() {
  $this->form['#validate'][] = [
    self::class,
    'formValidate',
  ];

  // Initialize validation information every time the form is rendered to
  // avoid stale data after a failed submission.
  $this->form_state
    ->setValue('conditional_fields_untriggered_dependents', []);
  return $this;
}