Skip to content
Snippets Groups Projects
Commit 6c2f3e79 authored by Dries Buytaert's avatar Dries Buytaert
Browse files

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

parent 2b367df8
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -271,9 +271,15 @@ function _form_builder($form_id, $form) {
}
}
if (!isset($form['#value'])) {
$function = $form['#type'] . '_value';
if (function_exists($function)) {
$function($form);
}
else {
$form['#value'] = $form['#default_value'];
}
}
}
if (isset($form['#form_submitted'])) {
if ($_POST[$form['#name']] == $form['#value']) {
$form_submitted = $form_submitted || $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']);
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment