0

I've a form created programatically with a few fieldset and some inputs in these use ajax callback. The structure is like this :

$form['global']['controls'] = [
  '#type' => 'fieldset'
];

$form['global']['info'] = [
  '#type' => 'fieldset'
];

$form['global']['description'] = [
  '#type' => 'fieldset'
];

I've defined a theme template in my .module file and created the twig template. This is the twig template :

<div>
  {{ form.global.info }}
  {{ form.global.controls }}
  {{ form.global.description }}
</div>

The form display correctly but ajax callback don't work : the callback are executed but don't change the elements.

All callbacks work with this :

<div>
  {{ form }}
</div>

But I can't rearange the form with this twig code.

What I want is the possibility to rearange the order of the fieldsets in twig : put the fieldset 'description' before 'info', or 'controls' before 'info', etc. And keep ajax callbacks working.

Is it possible? And how?

  • Rearrange the form elements in a custom template and add it to the form with $form['#theme'] , see drupal.stackexchange.com/questions/245127/… – 4k4 Sep 6 '18 at 18:41
  • I think you are missing something like this in your twig at the end: {{ form|without('global') }} AND maybe also this, depending on your form elements: {{ form.global|without('global') }} – Cesar Moore Sep 6 '18 at 19:01
0

The solution for this case was just to add {{ form|without('global') }} at the end of the .twig file, like this :

<div>
  {{ form.global.info }}
  {{ form.global.controls }}
  {{ form.global.description }}
</div>
{{ form|without('global') }}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.