- Issue created by @fathershawn
- First commit to issue fork.
- πΊπΈUnited States fathershawn New York
Posting some notes and code snippets from conversations in Slack. I'm not using the issue fork as we aren't really ready for that yet as there are still dependencies that need to be committed.
I loaded up the 11.x branch locally and spent more time stepping through
FormBuilder
,FormAjaxResponseBuilder::buildResponse
, andFormAjaxSubscriber::onException
with xdebug.- The form is definitely cached on an ajax interaction. This happens at
FormBuilder.php:436
- I reversed the actual effect of
FormAjaxSubscriber::onException
. The Ajax classes copy the new build ID back to the form.
So I removed the previous code to maintain build_id from my POC branch and instead added the following immediately after the
$form['form_build_id']
part of the form is built inFormBuilder::prepareForm
.// If a form is building from an HTMX request and the form id has changed // add htmx attributes to update the build ID in the client. // @see \Drupal\Core\Form\EventSubscriber\FormAjaxSubscriber::onException // @see Drupal.AjaxCommands.update_build_id if ($this->isHtmxRequest() && $form['#build_id'] !== $input['form_build_id']) { $existing_id = Html::getId($input['form_build_id']); $htmx_attributes = new HtmxAttribute(); $htmx_attributes->swapOob('outerHTML:input[data-drupal-selector="' . $existing_id . '"]'); $form['form_build_id']['#attributes'] = AttributeHelper::mergeCollections($form['form_build_id']['#attributes'], $htmx_attributes); }
We don't have all the similar tools available yet, but this would be adding
data-hx-swap-oob='outerHTML:input[data-drupal-selector="existing-form-build-id"]'
to the build id input element on the response.And that works! Validation is working, form_build_id is changing.
- The form is definitely cached on an ajax interaction. This happens at
- First commit to issue fork.
- π«π·France nod_ Lille
we need π Return htmx responses as SimplePageVariant Active before this works properly
- πΊπΈUnited States fathershawn New York
I pushed up a draft MR of how I imagine this implementation. I've commented out a condition that would depend on the upstream issue, but otherwise the single export form works here. My experience is that the form builder out of band swap needs to be deeper in the build process to prevent the validation error.
Nice edge case catch on the nested case with a full form swap @nod_!