I have two user defined elements:

hook_elements() {
	...
	$type['grid'] = array (
		'#tree' => TRUE,
	);
	
	$type['listbox'] = array(
		'#input' => TRUE,
		'#tree' => TRUE,
	);
	...
	return $type
}

so far so good but when I want to use the types like the next example:

	$form['test_grid'] = array(
		'#name' => 'test_grid',
		'#type' => 'grid',
		'#title' => t('Grid test'),		
	);
	
	$form['test_grid']['lb1'] = array(
		'#name' => 'lb1',
		'#type' => 'listbox',
		'#options' => array('optie 1', 'optie 2', 'optie 3'),
	);

the second type (listbox) does not show up. It shows up when I remove test_grid from the type. But I want to use variant in the example. Can anybody tell me how to use 'nested' elements?

Comments

estraver’s picture

anybody?

nevets’s picture

Here is an example of grouped elements (sort of nested) using the fieldset element

		$form['range'] = array('#type' => 'fieldset',
		 							'#title' => t('Range check'),
		  							'#collapsible' => TRUE,
		  							'#collapsed' => FALSE,
		  							'#description' => t('Only applies if value is numeric.  If set, used to check that user input is in the range specified.'));
		  											
		$form['range']['min_value'] = array('#type' => 'textfield', '#title' => t('Lower Value'),
	    '#size' => 32, '#maxlength' => 64,
	    '#description' => t('If set, valued entered as part of action must be greater than or equal to this value.'),
	    '#default_value' => $input->min_value);	
	
		$form['range']['max_value'] = array('#type' => 'textfield', '#title' => t('Upper Value'),
	    '#size' => 32, '#maxlength' => 64,
	    '#description' => t('If set, valued entered as part of action must be less than or equal to this value.'),
	    '#default_value' => $input->max_value)
estraver’s picture

Thanx, but that's not what I want. That works for the default elements fieldset, but I want that it works with my defined elements. So, if I want to use the group structure $form['a']['b'] with my own types grid and listbox (see first post) it doesn't work, but when I don't use a group like $form['a'] it works. There must be a reason why it doesn't work with my defined elements.

Hopefully someone can give some advise or an example how has to be.

magico’s picture

Status: Active » Fixed

Closing support request older than 1 month.

Anonymous’s picture

Status: Fixed » Closed (fixed)