How to reproduce the bug:
1. Create content type with select nodereference component using with example options (set as required!).
2. Create content using this type and select some values.
3. Edit this content.
4. Before Updating the content, please set component to read-only (disabled).
I.E. using the Firebug in Firefox, you can run from console:
$x('//*[@class="form-select required"]')[0].disabled=true
to disable it.
You can't update when component is read-only, because it not passing the reference validation.
There is an error:
This post can't be referenced.
Explanation:
When you have read-only component, it's not submitting value via _POST, it's getting it's default value (copying #default_value to #value).
Difference between normal select and nodereference select is that you receiving an array instead of string (no matter if it's multiple or not)
nodereference.module
function nodereference_widget()
...
case 'prepare form values':
$items_transposed = content_transpose_array_rows_cols($items);
$items['default nids'] = $items_transposed['nid'];
So this array is copied in form_builder() to #value
Later in nodereference_field() function (nodereference.module) you checking if array exists in array instead of string in array, so it's returning FALSE instead of TRUE.
2.5333 10116848 +648 -> in_array(array (0 => '7'), array (0 => 5, 1 => 6, 2 => 7, 3 => 8, 4 => 3)) C:\Users\bronek\workspace\websites\drupal57\modules\cck\nodereference.module:121
>=> FALSE
Even if pass this validation, you will have other problems during update the node using the array on non-multiple select.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | nodereference.module.patch | 789 bytes | kenorb |
| #1 | Clipboard01.jpg | 81.62 KB | kenorb |
Comments
Comment #1
kenorb commentedSee attachment.
Comment #2
kenorb commentedIt's similar problem also with multi-select component (without nodereference) and checkboxes.
For multi-select issue there is a patch here: http://drupal.org/node/236672
Comment #3
kenorb commentedTrace of using array instead of string during update the field:
Array: array (0 => array (0 => '5'), 1 => '7', 2 => '7')
is translated via db_query() to invalid values 1, 7, 7 instead of 5, 7, 7
Comment #4
kenorb commentedAfter patch, select are updating successfully (tested also on multi-select nodereferences).
Also in this patch there is another fix of some other bug, when values are copied from #default_value to #value they are not parsed via drupal_map_assoc() function in form_builder so they are in different format (array(0 => option1, 1=> option2, ...) instead of array(option1 => option1, option2 => option2, ...), so the first value will be always deleted
See nodereference_widget() function:
it's resolved by adding additional empty key (array_unshift).
Comment #5
moshe weitzman commentedthis is a general problem with disabled fields. see http://drupal.org/node/227966. please reopen if this problem is not a dupe of that one.
Comment #6
gcassie commentedI was able to work around this by setting the disabled field's value to it's default value in hook_form_alter.
It passes validation and doesn't wipe out the original value.
Comment #7
gcassie commentedTo do the same thing for userreference fields: