When reviewing http://drupal.org/node/690980 I discovered that the managed file field is not distributing the #disabled state or the 'disabled' attribute to it's internal elements, $element['upload'], $element['upload_button'], or $element['remove_button'].

This has the effect of allowing you to completely use the disabled managed file field, however doing this produces an error:

Warning: Cannot use a scalar value as an array in _form_set_value() (line 1897 of /Users/myuser/Sites/drupal/includes/form.inc).

Comments

crashtest_’s picture

StatusFileSize
new1.21 KB

Here is a patch for the file module.

chx’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 776956-managed-file-attributes.patch, failed testing.

lut4rp’s picture

Status: Needs work » Needs review
StatusFileSize
new1.21 KB

The patch attached in the issue doesn't apply cleanly, I re-rolled it, attaching again.

crashtest_’s picture

Status: Needs review » Active
StatusFileSize
new1.2 KB

Cleaned up whitespace.

cwgordon7’s picture

Status: Active » Needs review

The patches in #4 and #5 are identical except for the fact that #5 is not properly rolled (should be done from the Drupal root directory). Setting to needs review for #4. lut4rp, you'll need to repost that patch so the testing bot knows what's up.

lut4rp’s picture

StatusFileSize
new1.39 KB

Again, re-rolling and posting.

Status: Needs review » Needs work

The last submitted patch, 776956-managed-file-attribs-2re.patch, failed testing.

drewish’s picture

Status: Needs work » Needs review

That seems sane to me. I wonder if we'll need to make changes to the javascript though.

crashtest_’s picture

Status: Needs review » Active
StatusFileSize
new2.86 KB

Thanks to dmitrig01 for the js help on this patch!

This is still producing the following warning, however the disabled managed file fields stay disabled now.

Warning: Cannot use a scalar value as an array in _form_set_value() (line 1897 of /Users/pteglia/Sites/drupal/includes/form.inc).

crashtest_’s picture

Status: Active » Needs review
crashtest_’s picture

StatusFileSize
new2.43 KB

Cleaning up patch, removing console call.

berdir’s picture

We recently changed the behavior of #disabled, see #426056: Server-side enforcement of #disabled is inconsistent just wondering if there is anything to do because of that, for example, pass the #disabled attribute through too.

effulgentsia’s picture

subscribing for review later.

yesct’s picture

Status: Needs review » Needs work

The last submitted patch, 776956-managed-file-attributes-3.patch, failed testing.

catch’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 776956-managed-file-attributes-3.patch, failed testing.

mr.baileys’s picture

Status: Needs work » Needs review
StatusFileSize
new2.37 KB

Re-rolled to keep up with HEAD. I changed

'#attributes' => $element['#attributes']

to

'#disabled' => (isset($element['#disabled']) && $element['#disabled']),

as it feels icky to indiscriminately copy all attributes to the child components of the file element.

yesct’s picture

+++ modules/file/file.js	4 Jun 2010 08:38:53 -0000
@@ -102,7 +106,8 @@
+      .end().filter('.disabled').removeClass('disabled');

indenting might be needed here...

Powered by Dreditor.

yesct’s picture

left as needs review because I only looked at the style real quick, nothing functional.

chx’s picture

Title: Managed file field not respecting "#disabled" state » Complex widgets are not respecting "#disabled" state
Status: Needs review » Needs work

Make Form API inherit #disabled and slap a #disabled on the widget container in field.form.inc. This issue is not about file.

chx’s picture

Status: Needs work » Needs review
StatusFileSize
new1.65 KB

Ah so it's not a setting much rather something like the a form alter that adds a disabled. Then this little patch should suffice.

damien tournoud’s picture

StatusFileSize
new5.44 KB

Added two tests:

- #disabled is recursively validated (values below a #disabled container cannot be altered) [this was working before]
- #disabled is recursively added to the HTML [this is what this patch fixes]

Status: Needs review » Needs work

The last submitted patch, 776956-disabled-inherit.patch, failed testing.

damien tournoud’s picture

Status: Needs work » Needs review
StatusFileSize
new5.45 KB

And with a non-broken inheritance logic, it should pass better :)

chx’s picture

Status: Needs review » Reviewed & tested by the community

*blushes* OK. I am dumb. But the logic was sound :)

effulgentsia’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new6.36 KB
+++ includes/form.inc
@@ -1432,6 +1432,11 @@ function form_builder($form_id, $element, &$form_state) {
+    // Disable child elements if parent is disabled.
+    if (isset($element['#disabled'])) {
+      $element[$key]['#disabled'] = $element['#disabled'];
+    }
+

s/isset/!empty/

+++ modules/file/file.js
@@ -92,7 +92,11 @@ Drupal.file = Drupal.file || {
-    var $disabledFields = $('div.form-managed-file input.form-file').not($enabledFields);
+    var $disabledFields = $('div.form-managed-file input.form-file').not($enabledFields).each(function() {
+      if ($(this).is(':disabled')) {
+        $(this).addClass('disabled');
+      }
+    });
 
     // Disable upload fields other than the one we're currently working with.
     $disabledFields.attr('disabled', 'disabled');
@@ -102,7 +106,8 @@ Drupal.file = Drupal.file || {

@@ -102,7 +106,8 @@ Drupal.file = Drupal.file || {
     // re-enables the file fields after other processing is complete even though
     // it is only a 1 second timeout.
     setTimeout(function (){
-      $disabledFields.attr('disabled', '');
+      $disabledFields.filter(':not(.disabled)').attr('disabled', '')
+      .end().filter('.disabled').removeClass('disabled');
     }, 1000);

I had to read this 10 times before understanding what was being done. I changed it to what makes more sense to me. Please see if I captured the intent correctly.

60 critical left. Go review some!

chx’s picture

Status: Needs review » Needs work

whether !empty or isset, does not matter, who cares if we inherit #disabled false? I am fine with either, but it should check for !isset($element[$key]['#disabled']) so that we do not squash an existing one

effulgentsia’s picture

Are you sure? Don't we want it just like #access? What's the use-case for a disabled parent and a non-disabled child?

chx’s picture

I have no idea but if you explicitly set #dsabled to FALSE we better honor that. It's a very edge case.

effulgentsia’s picture

Status: Needs work » Needs review
StatusFileSize
new8.17 KB

Ok. In fact, it's what we were already doing for checkboxes and radios, so this cleans that up.

marcingy’s picture

Patch works as advertised with complex widgets. Although I think some more involved with the issue should mark it RTBC.

yesct’s picture

Status: Needs review » Needs work
+++ modules/simpletest/tests/form.test	24 Jun 2010 21:53:26 -0000
@@ -185,26 +185,43 @@ class FormsTestCase extends DrupalWebTes
+   * Assert that the values submitted to a form matches the default values of the elements.

line too long (80 char max)

45 critical left. Go review some!

effulgentsia’s picture

Status: Needs work » Needs review

From http://drupal.org/node/1354#general

Summary here; one sentence on one line (should not, but can exceed 80 chars).

coltrane’s picture

Status: Needs review » Reviewed & tested by the community

Still applies and works, also the disabled fields can't be gamed from what I can tell.

marcingy’s picture

#32: 776956-disabled-inherit-32.patch queued for re-testing.

effulgentsia’s picture

Title: Complex widgets are not respecting "#disabled" state » [beta blocker blocker] Complex widgets are not respecting "#disabled" state

According to http://drupal.org/community-initiatives/drupal-core, #690980: Disabled form elements not properly rendered is a beta blocker. This issue is a pre-req for it, making this issue a "beta blocker blocker". Reflecting that in the issue title.

sun’s picture

#32: 776956-disabled-inherit-32.patch queued for re-testing.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Sorry; took me awhile to get brain-space to look at this. And... looks good! And comes with tests to make sure it works.

Committed to HEAD. Thanks!

Status: Fixed » Closed (fixed)

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

marthinal’s picture

Version: 7.x-dev » 6.22
Priority: Critical » Major
Status: Closed (fixed) » Patch (to be ported)
StatusFileSize
new486 bytes

Little patch to disabled password_confirm correctly in D6.

albert volkman’s picture

Status: Patch (to be ported) » Needs review

Updating status. Ignore testbot fail.

Status: Needs review » Closed (outdated)

Automatically closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.