Problem/Motivation

AutoTextfields::textfieldsCallback() contains the following code.

  return $form['textfields_container'];

That is the wrong form element: AutoTextfields::buildForm() does not set $form['textfields_container'], but $form['text_fields_container'].

    // Wrap text fields in a container. This container will be replaced through
    // AJAX.
    $form['text_fields_container'] = [
      '#type' => 'container',
      '#attributes' => ['id' => 'text-fields-container'],
    ];
    $form['text_fields_container']['text_fields'] = [
      '#type' => 'fieldset',
      '#title' => $this->t("Generated text fields for first and last name"),
      '#description' => $this->t('This is where we put automatically generated text fields'),
    ];

Proposed resolution

Replace AutoTextfields::textfieldsCallback() with the following code.

  /**
   * Callback for ajax_example_auto_text_fields.
   *
   * Selects the piece of the form we want to use as replacement markup and
   * returns it as a form (renderable array).
   */
  public function textfieldsCallback($form, FormStateInterface $form_state) {
    return $form['text_fields_container'];
  }

Issue fork examples-3545346

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

avpaderno created an issue. See original summary.

avpaderno’s picture

Status: Active » Needs review
avpaderno’s picture

Component: AJAX Example » Code

  • avpaderno committed 2c4b556d on 4.0.x
    Issue #3545346: The AJAX callback for AutoTextfields returns the wrong...
avpaderno’s picture

Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.