Please see the following code:
foreach ($formaddresses as $key => $val) {
// Add edit buttons to custom client-side created addresses.
if (!isset($val['accountnumber'])) {
$form['orderinfo']['billshipaddresses']['billingaddresses'][$key]['#description'] = '<a class="edit-stored-address edit-stored-address-target-' . $key . '">Edit</a>';
$form['orderinfo']['billshipaddresses']['shippingaddresses'][$key]['#description'] = '<a class="edit-stored-address edit-stored-address-target-' . $key . '">Edit</a>';
}
}
Here this loop is creating some anchors in my form.
I just need to attach/add ‘#ajax’ callback to it.
How can I achieve this?
Something like the following code:
$form['orderinfo']['billshipaddresses']['shippingaddresses'] = [
'#type' => 'radios',
'#title' => 'Shipping Address',
'#options' => $formaddressesOptions,
'#default_value' => '',
'#ajax' => [
'callback' => '::buildShipBillAddresses',
'wrapper' => 'shippingaddresses',
'event' => 'change'
],
];
Here we can see if the above radio is change then an ajax callback will work and will call this method buildShipBillAddresses
Thanks!