Hello, This is working very well:

	$form['details'] = array(
	'#type' => 'fieldset',
	'#title' => t('Common Information'),
	'#tree' => TRUE,
	'#attributes' => array('class' => 'fieldset-details'),
	);

I can thee the fieldset-details class in the source code. But this doesn't work:

	$form['order-left'] = array(
	'#type' => 'item',
	'#prefix' => '<div class="global-order"><div class="order-left">',
	'#attributes' => array('class' => 'hide-item'),
	);

I cannot see the class in the source code.

It's the same with this:

	$form['results'] = array(
	'#attributes' => array('class' => 'buisness'),
	'#type' => 'item',
	'#title' => t('Price'),
	'#value' => _order_price_format_values(array('0' => '0 €')),
	);

I got the theming table and the title but the class doesn't appear. What's the problem ?

Thank you !

CommentFileSizeAuthor
#7 forms_api_reference.html_.patch2.25 KBsteven jones

Comments

damien tournoud’s picture

Project: French translation » Drupal core
Version: 6.x-1.0 » 7.x-dev
Component: PO files » forms system
Assigned: YoyoS » Unassigned
Category: bug » support
Priority: Critical » Normal
ainigma32’s picture

Title: Bug with attributes and items » FAPI docs inconsistent on allowed properties for #item
Project: Drupal core » Documentation
Version: 7.x-dev »
Component: forms system » Correction/Clarification
Category: support » bug

AFAICS this behavior is by design so the bug is in the API documentation for D6: http://api.drupal.org/api/file/developer/topics/forms_api_reference.html... shows that you can use the #attributes property for an #item while http://api.drupal.org/api/file/developer/topics/forms_api_reference.html... does not have #item in the Used by: section. AFAICS the latter is correct.

From form.inc line 1843 and further:

/**
 * Format a form item.
 *
 * @param $element
 *   An associative array containing the properties of the element.
 *   Properties used:  title, value, description, required, error
 * @return
 *   A themed HTML string representing the form item.
 *
 * @ingroup themeable
 */
function theme_item($element) {
  return theme('form_element', $element, $element['#value'] . (!empty($element['#children']) ? $element['#children'] : ''));
}

The code goes right to theme('form_element',... and does not process the #attributes property (as it says in the comments).

I'm marking this as a bug for documentation. If you want to use the #attributes property you should create a separate issue and mark it as a feature request for D7.x

- Arie

YoyoS’s picture

Thx for your answer. It's ok for me, i did it in another way. I used the suffix and prefix value to manage the item. I don't know if there is a better way. I'm a very beginner with drupal and about theming, I just know how to create a table :D

My little hack:

	$form['results'] = array(
	'#type' => 'item',
	'#prefix' => '<div id="buisnessresults">',
	'#suffix' => '</div>',
	'#value' => _order_price_format_values(array('0','0 €','0 €')),
	);

        function _order_price_format_values($form_state = array()) {
	$header = ...
	return theme('table', $header, $rows);
        }

If I understand you, I could do the same with your function

function theme_item($element) {
  return theme('form_element', $element, $element['#value'] . (!empty($element['#children']) ? $element['#children'] : ''));
}

If you could explain a little please :)

Thx you !

ainigma32’s picture

I just referred to the code in form.inc so you could see that the #attributes value isn't used for #item

I think your workaround looks just fine and you know what they say: if it ain't broken, don't fix it :-)

- Arie

add1sun’s picture

Project: Documentation » Drupal core
Version: » 7.x-dev
Component: Correction/Clarification » documentation

Core and API docs go in the Drupal project queue.

steven jones’s picture

Assigned: Unassigned » steven jones

Working on this...

steven jones’s picture

StatusFileSize
new2.25 KB

Here's a lovely little patch for the form API reference bit, because I seem to have lost commit access for the file. Patches will be needed for 6,5,4.7 etc.

steven jones’s picture

Version: 7.x-dev » 4.7.0

Fixed in D7 and D6 versions.

steven jones’s picture

Version: 4.7.0 » 5.0

Five needs work too!

steven jones’s picture

Status: Active » Fixed

Should now noe be fixed in all versions, please wait for a.d.o to refresh the content!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.