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.
Comment | File | Size | Author |
---|---|---|---|
#2 | form.inc_.patch | 432 bytes | kenorb |
#1 | Clipboard01.jpg | 127.26 KB | kenorb |
Comments
Comment #1
kenorb CreditAttribution: kenorb commentedBasically 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.
Comment #2
kenorb CreditAttribution: kenorb commentedThe problem is in form_builder Drupal function (form.inc):
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:
Patch in attachment.
Comment #3
kenorb CreditAttribution: kenorb commentedFor patch of similar bug for multi-select component when using nodereferences you can find here:
http://drupal.org/node/241704#comment-792111
Comment #4
kenorb CreditAttribution: kenorb commented.
Comment #5
kenorb CreditAttribution: kenorb commentedI 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.
Comment #6
drummThis 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.
Comment #7
kenorb CreditAttribution: kenorb commentedDrupal 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():
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.
Comment #8
kenorb CreditAttribution: kenorb commentedFor 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.
Comment #9
kenorb CreditAttribution: kenorb commentedComment #10
kenorb CreditAttribution: kenorb commentedComment #11
kenorb CreditAttribution: kenorb commented