Hi,
I've created a form and themed it as a table using D7 form API.
I want to add a 'delete' button to each row that will remove the row on which the button was clicked (via Ajax - w/o page refresh).
My problem is: how to determine inside the Ajax callback function which row was clicked?
Each row had a unique id, each button has a unique name and id, I can see in the $form_state that there is an entry called: "_triggering_element_name" which contains the name of the clicked button, but somehow it doesn't seem to be a the correct way to do it...
some code:
// form build
function form_build {
...
for ($i ... ) {
$form['items']["delete$i"] = array(
'#type' => 'submit',
'#name' => "remove$i",
'#value' => t('Delete'),
'#submit' => array('myform_del_item'),
'#ajax' => array(
'callback' => 'mymodule_form_callback_items',
'wrapper' => 'item-div',
'effect' => 'fade',
'progress' => array('type' => 'none'),
),
);
}
}
/**
* only select the portion of the form to be updated.
*/
function mymodule_form_callback_items($form, $form_state) {
return $form['items'];
}
/**
* Submit handler for the "delete" button.
*/
function myform_del_item($form, &$form_state) {
// 1. get row id / button id ???
// 2. delete row