There seems to be a prolem with form building when Javascript is enabled on multivalue fields and "Add another item":
I use form_alter to provide default values for my custom cck field, consisting of 3 textfields.
It works nice for the 2 default items. they get filled with the values I set in form_alter.
- If JS is disabled in the browser, all further items are populated, too.
- If JS is enabled, I can do what I want, the form doesn't set the default values.
I tried form_alter and after_build
fmi:
setting after_build on form_alter for javascript call ($form_id = content_add_more_js) like
$form['#after_build'][] = 'cck_inputs_checkbox_checkbox_process_afterbuild';
doesn't trigger it.
But it gets triggered when registered on the standard form_alter call.
code runs like this:
on "create node":
standard form_alter (with registering after_build )
after_build
on "add another item":
after_build
form_alter javascript
after_build
/fmi
what I found out is this:
after this call to form_builder in content_add_more_js:
$form = form_builder($_POST['form_id'], $form, $form_state);
the form is populated inconsistently for default values:
......
[1] => Array
(
[#type] => cck_inputs_checkbox_checkbox
[#default_value] => Array
(
[checkbox_label] => Seat 1
[checkbox_name] => checkbox_name_1
[checkbox_value] => 1
)
........
[checkbox_label] => Array
(
[#title] => Checkbox label
[#type] => textfield
[#default_value] => Seat 1
........
[2] => Array
(
[#type] => cck_inputs_checkbox_checkbox
[#default_value] => Array
(
[checkbox_label] => Seat 3
[checkbox_name] => checkbox_name_3
[checkbox_value] => 3
)
......
[checkbox_value] => Array
(
[#title] => Checkbox value
[#type] => textfield
[#default_value] =>
..........
on the newly added item [2] the default value is not set. only for the widget.
Comments
Comment #1
jzornig commentedI'm having this problem with a filefield. I have a default value set for a "list" checkbox. When I "Add another item" the default value is not set. However if I disable javascript in my browser and try again, the default is set correctly.
See http://drupal.org/node/636548 for more details.
Comment #2
geshan commentedI'm also stuck at similar problem, default value does not work. :(
Comment #3
US Drupal Development commentedI experienced this with a SELECT form item. I printed out the new form from the ahah function and noticed that #value was set to my original #default_value. On a hunch, I set both the #default_value and #value to my desired updated default value, and sure enough it worked.