If you create a form and make that some checkboxes have an ajax actions (for example, when you check one checkbox, another field will be updated), the checkbox renderization are buggy.

See the attached image for more details.

This is the form field definition:

    $form['country'] = [
       '#type' => 'checkboxes',
       '#options' => $countries,
        '#ajax' => [
          'callback' => [$this, 'rebuildProvinces'],
          'event' => 'change',
          'wrapper' => 'edit-province',
        ],
      ];
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

estoyausente created an issue. See original summary.

markhalliwell’s picture

Pretty sure this has something to do with the JavaScript ajax handling in http://cgit.drupalcode.org/bootstrap/tree/js/misc/ajax.js or some other JS file where it's trying to wrap in an input group (so it looks decent); like with select elements.

torgosPizza’s picture

I think is may be a duplicate of #2121203: Better Exposed Filters Checkboxes.

fearlsgroove’s picture

Status: Active » Needs review
FileSize
889 bytes

Checkboxes simply don't work in input-groups with ajax, mostly because they're wrapped in labels. Theoretically you could drastically alter the markup to accommodate it, but it's not really worth it. Attached patch excludes checkbox(es) from the input-group processing. Should probably also happen with radios.

markhalliwell’s picture

Component: CSS Overrides » Plugin System
Status: Needs review » Needs work
+++ b/src/Plugin/ProcessManager.php
@@ -92,7 +92,7 @@ class ProcessManager extends PluginManager {
+    if (!$element->isType('hidden') && !$element->isType('checkbox') && !$element->isType('checkboxes') && (!isset($ajax['progress']['type']) || $ajax['progress']['type'] === 'throbber')) {

Element::isType can take an array of strings, no need for multiple invocations of the method.

May as well go ahead and put radios in here as well.

---

I'd also like to see a screenshot of a before and after with this patch applied so I can see the visual difference.

markhalliwell’s picture

Status: Needs work » Fixed
FileSize
1.22 KB

  • markcarver committed 93225b0 on 8.x-3.x
    Issue #2762225 by fearlsgroove, estoyausente, markcarver: Checkbox with...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.