8 – Changing 2 Elements on Ajax Callback


I have an element $form('elements')('manufacturer'). On change, I want to change $form('elements')('form_factor') and $form('elements')('model').

Currently I have:

$form('elements')('manufacturer')('#ajax') = (
    'callback' => 'formChanged',
    'wrapper' => 'form-factor',
    'event' => 'change',
);

which works and changes the form-factor. But, I want to change the model as well.

Iniside formChanged return form-factor in the callback function, so I can’t return model element.

function formChanged(array &$form, FormStateInterface $formState){
  $form("elements")("form_factor")("#value") = 0;
  return $form("elements")("form_factor");
}

Reading from past posts, one option was to return the whole form inside formChanged (return $form), but this doesn’t seem like a good approach.

I can’t do something like, having 2 callbacks:

$form('elements')('manufacturer')('#ajax') = (
   (
    'callback' => 'formChanged',
    'wrapper' => 'form-factor',
    'event' => 'change',
   ),
   (
    'callback' => 'anothercallback',
    'wrapper' => 'another-one',
    'event' => 'change',
   )
);