Add new comment | Drupal 8

Add new comment

This happens if you add the fields on the callback function. The form doesn't get rebuilt at this point, so the values on the new fields are discarded. You need to add the fields on buildForm function by checking on the $form_state values.

On the simplest case, you can check that the triggering field has a value set and then conditionally build the new field as per defined functionality. Then on the callback you just need to call:

return $form['wrapper_of_the_element_to_change'];

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.