How to reproduce the bug:
1. Create some Test content type
2. Add text/select (Select list) field to already created content type
3. Add some examples to 'Allowed values list' and set to Required
4. Go to Create content page
5. Try to disable this component
You can do it in different ways:
- using Firefox with Firebug installed you can run followed command in Firebug console:
$x('//*[@class="form-select required"]')[0].disabled=true
- or you can also disable it from Firebug adding to
tag: disabled='disabled'
- or directly from some module
$form['field_test'][0]['key']['#attributes'] = array('disabled' => 'disabled');
6. Make sure that you select some option (is required, so you'll have always selected option)
7. Try to Submit it
And there will be error that this field is required.
How?

Similar problem with checkboxes when are disabled.
With Date, radios, textfield is suppose to working.

CommentFileSizeAuthor
#2 form.inc_.patch432 byteskenorb
#1 Clipboard01.jpg127.26 KBkenorb
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kenorb’s picture

FileSize
127.26 KB

Basically it's problem when you trying to update the content and you have read-only (disabled) multi-select component.

See attachment.
All options before submit has been set and all components has been set to disabled.

kenorb’s picture

Project: Content Construction Kit (CCK) » Drupal core
Version: 5.x-1.x-dev » 5.x-dev
Component: optionwidgets.module » forms system
Status: Active » Needs review
FileSize
432 bytes

The problem is in form_builder Drupal function (form.inc):

            case 'select':
              if (isset($form['#multiple']) && $form['#multiple']) {
                if (isset($edit) && is_array($edit)) {
                  $form['#value'] = drupal_map_assoc($edit);
                }
                else {
                  $form['#value'] = array();
                }
              }

If #value is not set, it's setting value to empty ($form['#value'] = array();) without checking for correct value from the #default_value.

So after that, followed code will be ignored and value will be invalid:

      if (!isset($form['#value'])) {
        $function = $form['#type'] . '_value';
        if (function_exists($function)) {
          $function($form);
        }
        else {
          $form['#value'] = isset($form['#default_value']) ? $form['#default_value'] : '';
        }
      }

Patch in attachment.

kenorb’s picture

Title: disabled dropdown is no passed on » disabled select (dropdown) is no passed on

For patch of similar bug for multi-select component when using nodereferences you can find here:
http://drupal.org/node/241704#comment-792111

kenorb’s picture

Version: 7.x-dev » 5.x-dev
Category: feature » bug
Priority: Critical » Normal
Status: Needs work » Needs review

.

kenorb’s picture

Title: disabled select (dropdown) is no passed on » values of disabled multiple select (dropdown) and checkbox are invalid after submitting the form
Priority: Normal » Critical

I think it's critical bug, because you can overwrite default values in database (without changing anything) of selected components during submitting the form when you'll disable a component in the browser.

drumm’s picture

Version: 5.x-dev » 7.x-dev
Category: bug » feature
Status: Needs review » Needs work

This is how HTML works. From http://www.w3.org/TR/html401/interact/forms.html#h-17.13.2, "Controls that are disabled cannot be successful [included in submitted form data]."

As a general rule, you should probably not make required elements disabled since that is a bit of a contradiction.

Drupal could provide the existing value for disabled form elements, but that is an API change, which would need to happen in the development version.

kenorb’s picture

Drupal 5.x is already providing the existing value from disabled form elements using the default_value during update.
It's working for most components, like selects, radios, for each where is executed followed line in form_builder():

$form['#value'] = isset($form['#default_value']) ? $form['#default_value'] : '';

but some components are overwritting #value with invalid value before above line will be not executed, so it's bug when you have in form fields with attribute 'disabled', then you can't update the content type at all.

kenorb’s picture

Version: 5.x-dev » 7.x-dev
Category: bug » feature
Priority: Normal » Critical
Status: Needs review » Needs work

For checkboxes you have right that it's not possible to determine default value, but for multiple select it's possible to determine default value and after using above patch is working.

kenorb’s picture

Priority: Critical » Normal
kenorb’s picture

Issue summary: View changes
Status: Needs work » Closed (outdated)
kenorb’s picture

Status: Closed (outdated) » Closed (works as designed)