I’ve added a custom ajax callback to a field that I’m trying to update the value of. The Field I’m updating is inside a field group and instead of updating the field it just empties the html.
The form item with the ajax callback
$form('sku') = (
'#type' => 'entity_autocomplete',
'#title' => $this->t('SKU'),
'#target_type' => 'node',
'#selection_handler' => 'views',
'#selection_settings' => (
'view' => (
'view_name' => 'parts_reference',
'display_name' => 'entity_reference_1',
'arguments' => ()
),
'match_operator' => 'CONTAINS'
),
'#weight' => '0',
'#size' => '200',
'#ajax' => (
'callback' => '::oeRefAjaxCallback',
// don't forget :: when calling a class method.
//'callback' => ($this, 'myAjaxCallback'), //alternative notation
'disable-refocus' => FALSE,
// Or TRUE to prevent re-focusing on the triggering element.
'event' => 'change',
// This element is updated with this AJAX callback.
'progress' => (
'type' => 'throbber',
'message' => $this->t('Verifying entry...'),
),
)
);
The form item that is to be updated
$form('item_specifics_type') = (
'#title' => 'Type',
'#type' => 'textfield',
'#value' => '',
'#size' => '60',
'#group' => 'fieldset_item_specifics',
'#prefix' => '<div id="item-specific-type-wrapper">',
'#suffix' => '</div>'
);
—
$response->addCommand(new HtmlCommand('#item-specific-type-wrapper', $form('item_specifics_type')));
If I remove the group key from the field array so that the field is not in the fieldset then the ajax command replaces the field with the correct html as expected.