- 🇬🇧United Kingdom 2dareis2do
Also does not have reset input
- 🇦🇲Armenia murz Yerevan, Armenia
Until this is fixed, as a workaround you can use two approaches for now:
1. Use the form redirect like this:public function buildForm(array $form, FormStateInterface $form_state) { ... $form['input_data']['options']['clear'] = [ '#type' => 'input', '#value' => $this->t('Reset'), '#limit_validation_errors' => [], '#submit' => [[$this, 'resetForm']], ]; return $form; } public function resetForm(array &$form, FormStateInterface $form_state): void { // A workaround for the issue // https://www.drupal.org/project/drupal/issues/2799269 $form_state->setRedirect('<current>'); }
2. Use the browser API to reset the form:
$form['reset'] = [ '#type' => 'input', '#value' => $this->t('Reset'), '#limit_validation_errors' => [], '#attributes' => [ 'onclick' => 'this.form.reset(); return false;', ]; );
But the proper API from Drupal Core would be much better, so keeping the issue as active.