How can I add independent child element to a radios element in a form?
The radio elements are created by the following code.
$form['orderinfo']['billshipaddresses']['billingaddresses'] = [
'#type' => 'radios',
'#title' => 'Billing Address',
'#options' => $formaddressesOptions,
'#default_value' => '',
'#ajax' => [
'callback' => '::buildShipBillAddresses',
'wrapper' => 'billingaddresses',
'event' => 'change'
]
];
In options, I set an associative array to make all radio. In them, I need to inject an Edit link/button with an AJAX callback, as in the following screenshot.
This is the code I am using for the Edit link:
private function formAddressesToOptions($formaddresses) {
$formaddressesOptions = [];
if (!empty($formaddresses)) {
foreach ($formaddresses as $key => $formaddress) {
if (isset($formaddress['accountnumber'])) {
$formaddressesOptions[$key] = $this->formatAddress($formaddress);
} else {
$formaddressesOptions[$key] = $this->formatAddress($formaddress) . "<span class='edit-newly-created-address'>Edit</span>";
}
}
}
return $formaddressesOptions;
}
The Edit link is shown below each radio, but it has no AJAX callback on its own. How can I achieve that properly?