Form class private member variable null in submitForm when form uses AJAX

Created on 2 September 2023, over 1 year ago
Updated 23 October 2023, about 1 year ago

Problem/Motivation

When a Drupal form uses AJAX, member variables lose their values when submitForm() is invoked.

Steps to reproduce

  1. Create a custom form with AJAX
  2. Add a private RendererInterface member variable to the class
  3. Use dependency injection to initialize the variable in the constructor
  4. In the submitForm() method display a message indicating whether the member variable's value is empty or set
  5. Load the form and submit it
  6. Read the message displayed by submitForm()

Proposed resolution

Ensure that the object handling the submitForm() method is a properly initialized instance of the custom form class.

Remaining tasks

Fix the bug.

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

Fixed bug in initialization of form objects with AJAX.

πŸ› Bug report
Status

Postponed: needs info

Version

10.1 ✨

Component
FormΒ  β†’

Last updated 2 days ago

Created by

πŸ‡ΊπŸ‡ΈUnited States bkline Virginia

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024