Commit 6c2f3e79 authored by Dries's avatar Dries
Browse files

- Patch #39179 by chx et al: fix checkboxes #default_values.

parent 2b367df8
......@@ -271,7 +271,13 @@ function _form_builder($form_id, $form) {
}
}
if (!isset($form['#value'])) {
$form['#value'] = $form['#default_value'];
$function = $form['#type'] . '_value';
if (function_exists($function)) {
$function($form);
}
else {
$form['#value'] = $form['#default_value'];
}
}
}
if (isset($form['#form_submitted'])) {
......@@ -585,6 +591,17 @@ function map_month($month) {
return format_date(gmmktime(0, 0, 0, $month, 2, 1970), 'custom', 'M', 0);
}
/**
* Helper function to load value from default value for checkboxes
*/
function checkboxes_value(&$form) {
$value = array();
foreach ((array)$form['#default_value'] as $key) {
$value[$key] = 1;
}
$form['#value'] = $value;
}
/**
* Roll out a single radios element
* to a list of radios, using the options array as index.
......@@ -667,7 +684,7 @@ function expand_checkboxes($element) {
}
foreach ($element['#options'] as $key => $choice) {
if (!isset($element[$key])) {
$element[$key] = array('#type' => 'checkbox', '#processed' => TRUE, '#title' => $choice, '#default_value' => in_array($key, $value), '#attributes' => $element['#attributes']);
$element[$key] = array('#type' => 'checkbox', '#processed' => TRUE, '#title' => $choice, '#default_value' => isset($value[$key]), '#attributes' => $element['#attributes']);
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment