I've tried to use the #states attribute to manage visibility (or enabled/disabled state) on a managed_file and it had no effect at all.

	'#title'=>t('Ad picture source'),
	'#options' => array('upload'=>t('File Upload'),'url'=> t('URL')),
	'#title'=>t('Ad picture file'),

Changing 'managed_file' by 'file' (or any other type) in this code works fine.

#14 1118016-states-managed_file-date-14.patch1.63 KBpwolanin
PASSED: [[SimpleTest]]: [MySQL] 32,910 pass(es). View
#11 1118016-states-managed_file-date.patch1.65 KBdawehner
PASSED: [[SimpleTest]]: [MySQL] 32,900 pass(es). View
#8 1118016-states-managed_file.patch898 bytesdawehner
PASSED: [[SimpleTest]]: [MySQL] 32,908 pass(es). View
Members fund testing for the Drupal project. Drupal Association Learn more


neoglez’s picture

Version: 7.0 » 7.2
Component: file system » javascript

yap, bug confirmed.
it happens to me exactly as described above.

coolestdude1’s picture

Confirmed same problem, even tried using invisible and visible together and still managed file stays visible in the form. Will be leaving the code in because no error is thrown (dblog, javascript alert, javascript console).

coolestdude1’s picture

Priority: Normal » Major

Just found that the same problem exists for date form type. Elevating priority because of this.

marcingy’s picture

Version: 7.2 » 8.x-dev
Priority: Major » Normal
Issue tags: +needs backport to D7

A work around for this is add items into a field set and then control visiablity based on the field, not ideal I admit but at the same time enough to put this back down to normal I believe. Also as it is a bug needs to go to d8 and be backported.

pwolanin’s picture

Priority: Normal » Major

Just ran in to this too - very annoying. I would consider this major. #states is broken.

rfay’s picture


olafkarsten’s picture


dawehner’s picture

Status: Active » Needs review
898 bytes
PASSED: [[SimpleTest]]: [MySQL] 32,908 pass(es). View

Justed runned into this as well, and i would say file_managed_file_process is broken...

Some reasons for this:

  • It adds a $id-ajax-wrapper around the widget, which seems to be not normal on drupal
  • It adds never the $id of the file_managed element.

Another thing i realized is that theme_file_managed_file doesn't add the id. Here is a patch which does this
and wooot this works.

Personally i fear that there are other form element which doesn't support this as well. For example theme_date looks somehow bad,
as well as tableselect, and perhaps many more.

dawehner’s picture

Component: javascript » file.module

Update the component.

pwolanin’s picture

Yes, there is a note above about it also being broken for date fields.

dawehner’s picture

1.65 KB
PASSED: [[SimpleTest]]: [MySQL] 32,900 pass(es). View

This patch fixes the date theme element as well.

I'm wondering whether all places should be fixed, or whether there should be created new issues.

prinds’s picture

A tip.. Until this patch is ported to v7 you can use a theme override to fix this in your theme or module..

function THEME_file_managed_file($variables) {
  $element = $variables['element'];
  $attributes = array();
  if (isset($element['#id'])) {
    $attributes['id'] = $element['#id'];
  $attributes['class'] = 'form-managed-file';
  if (!empty($element['#attributes']['class'])) {
    $attributes['class'] .= ' ' . implode(' ', $element['#attributes']['class']);
  // This wrapper is required to apply JS behaviors and CSS styling.
  $output = '';
  $output .= '<div' . drupal_attributes($attributes) . '>';
  $output .= drupal_render_children($element);
  $output .= '</div>';
  return $output;

for modules you should use the hook_theme_registry_alter to override..

pwolanin’s picture

I think you want to keep the classes as an array to pass to drupal_attributes

pwolanin’s picture

1.63 KB
PASSED: [[SimpleTest]]: [MySQL] 32,910 pass(es). View
jessebeach’s picture

Status: Needs review » Reviewed & tested by the community

This patch adds standard drupal_attributes pass-through that should have existed already to theme_date and theme_file_managed_file. It's ready to be committed.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Awesome, thanks folks. My kingdom for a JS test suite. :)

Committed and pushed to 8.x and 7.x.

Status: Fixed » Closed (fixed)
Issue tags: -needs backport to D7

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

Anonymous’s picture

Issue summary: View changes

Fixed typo