- Issue created by @fathershawn
- First commit to issue fork.
In general, \Drupal\Core\Form\FormBuilder
is aware of ajax api requests and needs to be adjusted so that it is similarly aware of HTMX requests.
A thorny problem with dynamic elements was encountered in
π
[POC] Implementing some components of the Ajax system using HTMX
Active
.
The form used as our discovery and development context for this POC, \Drupal\config\Form\ConfigSingleExportForm
, has <select>
elements with values that dynamically change based on user input.
With form builder as it is, if the form route is called with user input that is not a submit, the form rebuilds with a new build ID and fails to validate because the options get reset to their base case, and the user input no longer matches the available options.
Once we have dependent issues committed, I'll update ConfigSingleExportForm
without changing FormBuilder
so others can see the issue and explore solutions.
In the POC I solved the problem like this.
if ($this->isHtmxRequest()) {
// Restore the build id that was sent with the request. It will be used
// after the rebuild to cache the rebuilt form.
$form_state->addRebuildInfo('copy', ['#build_id' => TRUE]);
$input = $form_state->getUserInput();
$form['#build_id'] = $input['form_build_id'];
}
Refactor FormBuilder
Add appropriate tests
Active
11.0 π₯
ajax system