I have a standard form with a table. I can add lines to the table via AJAX.
I also like to delete the lines using AJAX. But I don't know exactly where and how to add the buttons.
Here is my code to build the table inside the standard form building function:
...
$aPersonsTable = array();
foreach ($aPersons as $key => $value) {
$row = array($value['dname'],'HERE IS THE PLACE WHERE THE BUTTON SHOULD SHOW UP');
$aPersonsTable[]=$row;
}
$form['persons']['ptable'] = array(
'#theme' => 'table',
'#header' => $pheader,
'#rows' => isset($aPersonsTable)?$aPersonsTable:null,
'#disabled' => TRUE,
'#title' => 'Users currently assigned',
'#empty' => t('No users assigned yet!'),
'#prefix' => '<div id="ptable_wrapper">',
'#suffix' => '</div>',
);
...
I'd like to have the button at 'HERE IS THE PLACE WHERE THE BUTTON SHOULD SHOW UP' :-)
I tried something like:
$row = array($value['dname'],array(
'#type' => 'submit',
'#value'=> 'Delete person',
'#attributes' => array('id'=>$value['id']),
'#ajax'=> array(
'callback' => 'delete_person_ajax_callback',
)
));
Any ideas? I googled and stackexchanged a lot, but did not find the right solution. Thx.
#ajax
property per button. I have a form with dozens AJAX buttons, 4 different callbacks, and it works.