By Andric Villanueva on
I have a table that is drag-drop enabled already.
I have an issue with adding extra form fields to a sortable table.
function step_three(&$form, &$form_state)
{
$arrLeftContestants = $form_state['bracket']->step_two['left']; // Bunch o' info
for ($i = 0; $i < count($arrLeftContestants); $i++)
{
$element['test-textfield-' . $i]
= array('#title' => t(''),
'#type' => 'textfield',
'#id' => 'text-' . $arrLeftContestants[$i]->cid,
'#default_value' => 'hey ' . $arrLeftContestants[$i]->cid);
$item = drupal_render($element['test-textfield-' . $i])
$data = array($arrLeftContestants[$i]->cid, $item);
$form['rows-left'][$arrLeftContestants[$i]->cid]['data']
= array('#type' => 'value',
'#value' => $data);
$form['rows-left'][$arrLeftContestants[$i]->cid]['weight-left-' . $arrLeftContestants[$i]->cid]
= array('#type' => 'weight',
'#default_value'=> $i,
'#attributes' => array('class' => 'weight weight-left'),);
}
$form = createDivisionArray($form, $form_state);
return $form;
}
That creates the array that will be theme'd
This function themes the array. It is registered in my module hook_theme function. I could do this in one step but I'm using ctools' form wizard API and it's cleaner anyway
function theme_step_three(&$form)
{
foreach ($form['rows-left'] as $id => $row)
{
if (is_int($id))
{
$this_row = $row['data']['#value'];
$this_row[] = drupal_render($form['rows-left'][$id]['weight-left-' . $row['data']['#value'][0]]);
$table_rows[] = array('data' => $this_row, 'class' => 'draggable');
}
}
// Make sure the header count matches the column count
$header = array('Left Division', 'something', Order);
$output = theme('table', $header, $table_rows, array('id' => 'left'));
drupal_add_tabledrag('left', 'order', 'sibling', 'weight-left');
return $output;
}
The issue is that I want to get $element['test-textfield-' . $i] registered with the form so that I can use it to
- Get the form_state values
- Add more form elements to the draggable table
I can upload the full code module if it will be easier. I don't mind. The code snippets I'm sure aren't the easiest things to work with
Thank you very much,
A.Villanueva