Don't really know if this is a tableselect issue or a noderefence issue but here goes:
I'm trying to implement the tableselect element in a hook_form_alter on a cck nodereference checkboxes form. If I just alter the checkboxes type to a tableselect no options are presented in the table. And if I load in the options myself it doesn't seem to pass the cck validation. Does anyone have an idea of how to aproach this the best way? You will most definatly save someones ass xD.
Here is what I've got so far:
$options = relation_nodes_get_options(); //copy of the "function _nodereference_potential_references_views(....)" to get the options from a certain view.
$header = array(
'title' => 'Name',
'rendered' => 'Price',
);
$form['field_sales_item']['#type'] = 'tableselect';
$form['field_sales_item']['#header'] = $header;
$form['field_sales_item']['#options'] = $options;
$form['field_sales_item']['#parents'] = array(
0 =>'field_sales_item',
1 =>'nid',
2 =>'nid',
);
$form['field_sales_item']['#array_parents'] = array(
0 =>'field_sales_item',
1 =>'nid',
2 =>'nid',
);
When I submit this form I get an "invalid input" message from nodereference validation. What am I overlooking here?
Comments
Comment #1
Dave ReidWhat is the result/data structure of relation_nodes_get_options()?
Comment #2
FrUitCaKe.be CreditAttribution: FrUitCaKe.be commentedThe result is an array of options and each option is structured like this:
[166] => Array ( [title] => mytitle [rendered] => extra fields )
where 166 is the 'nid'Whenever I create the form next to the original nodereference form and assign the same parents, the nodereference form accepts and stores the selections from the tableselect form. So maybe by altering the original form I'm doing something to the structure in wich normal checkboxes are processed? I'm really getting confused :(
Comment #3
FrUitCaKe.be CreditAttribution: FrUitCaKe.be commentedAny idea's?
Comment #4
letapjar CreditAttribution: letapjar commentedThe only place where "invalid input" occurs in nodereference is in
function nodereference_field($op, &$node, $field, &$items, $teaser, $page) {...
here is the relevant code:
the invalid input message occurs on line 216 of nodereference.module.
Seems like it is expecting and array with an array key of 'nid' and the actual nid in the value. you have your options array with numeric key corresponding to the nids.
perhaps you could try adding the nid key manually - i.e. after the
function relation_nodes_get_options() gives you and array try
foreach($options as $nid=>$option){
$option['nid']=$nid;
}
this *might* make the validation routine happy.
Comment #5
NancyDru6.x no longer supported