Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
$form['source']=array(
'#title'=>t('Ad picture source'),
'#type'=>'radios',
'#required'=>TRUE,
'#options' => array('upload'=>t('File Upload'),'url'=> t('URL')),
'#default_value'=>'',
'#weight'=>-2.2,
);
$form['ad_file']=array(
'#title'=>t('Ad picture file'),
'#type'=>'managed_file',
'#required'=>FALSE,
'#default_value'=>'',
'#weight'=>-2.1,
'#states'=>array(
'visible'=>array(
':input[name="source"]'=>array('value'=>'upload')
),
),
);
Changing 'managed_file' by 'file' (or any other type) in this code works fine.
Comment | File | Size | Author |
---|---|---|---|
#14 | 1118016-states-managed_file-date-14.patch | 1.63 KB | pwolanin |
#11 | 1118016-states-managed_file-date.patch | 1.65 KB | dawehner |
#8 | 1118016-states-managed_file.patch | 898 bytes | dawehner |
Comments
Comment #1
neoglez CreditAttribution: neoglez commentedyap, bug confirmed.
it happens to me exactly as described above.
Comment #2
coolestdude1 CreditAttribution: coolestdude1 commentedConfirmed 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).
Comment #3
coolestdude1 CreditAttribution: coolestdude1 commentedJust found that the same problem exists for date form type. Elevating priority because of this.
Comment #4
marcingy CreditAttribution: marcingy commentedA 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.
Comment #5
pwolanin CreditAttribution: pwolanin commentedJust ran in to this too - very annoying. I would consider this major. #states is broken.
Comment #6
rfaysubscribe
Comment #7
olafkarsten CreditAttribution: olafkarsten commentedsubscribe
Comment #8
dawehnerJusted runned into this as well, and i would say file_managed_file_process is broken...
Some reasons for this:
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.
Comment #9
dawehnerUpdate the component.
Comment #10
pwolanin CreditAttribution: pwolanin commentedYes, there is a note above about it also being broken for date fields.
Comment #11
dawehnerThis 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.
Comment #12
prinds CreditAttribution: prinds commentedA tip.. Until this patch is ported to v7 you can use a theme override to fix this in your theme or module..
for modules you should use the hook_theme_registry_alter to override..
Comment #13
pwolanin CreditAttribution: pwolanin commentedI think you want to keep the classes as an array to pass to drupal_attributes
Comment #14
pwolanin CreditAttribution: pwolanin commentedComment #15
jessebeach CreditAttribution: jessebeach commentedThis 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.
Comment #16
webchickAwesome, thanks folks. My kingdom for a JS test suite. :)
Committed and pushed to 8.x and 7.x.
Comment #17.0
(not verified) CreditAttribution: commentedFixed typo