Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I am using Drupal 7.17 but I found this bug haven't fixed in 7.x-dev. This issue and fixed are same as issue #1100170.
If within code processing AJAX request I set default value of checkboxes this default value is ignored by forms system and all checkboxes are instead created as unchecked.
I tracked down the issue to its origin and provide patch fixing this issue.
The patch is in line 3178 in includes/form.inc in Drupal 7 and it's working for me:
- '#default_value' => isset($value[$key]) ? $key : NULL,
+ '#default_value' => isset($value[$key]) || (is_array($element['#default_value']) && in_array($key, $element['#default_value'])) ? $key : NULL,