"Select all checkbox option?

Highlighted
Anonymous
Not applicable

"Select all checkbox option?

This might be very obvious and I'm missing it, but is there an option in Forms with a checkbox for "Select all"?

Tags (1)
3 REPLIES 3
Highlighted
Anonymous
Not applicable

Re: "Select all checkbox option?

No there is not an option for this.  You would have to do this via javascript

Highlighted
Level 10 - Community Moderator

Re: "Select all checkbox option?

Add a checkbox with the value "*".  Then

MktoForms2.whenReady(function(form) {

  var formEl = form.getFormElem()[0],

    _forEach = Array.prototype.forEach,

    selCheckboxGroups = '.mktoCheckboxList',

    selWildcardBox = 'input[value="*"]',

    selStandardBoxes = 'input:not([value="*"])';

  (function makeSelectAll() {

    _forEach.call(formEl.querySelectorAll(selCheckboxGroups), function(boxGroup) {

      boxGroup.querySelector(selWildcardBox).addEventListener('change', function(e) {

        _forEach.call(boxGroup.querySelectorAll(selStandardBoxes), function(box) {

          box.checked = this.checked;

        }.bind(this));

      });

    });

  })();

});

Demo: http://s.codepen.io/figureone/debug/JKvRQv

Highlighted
Anonymous
Not applicable

Re: "Select all checkbox option?

Very cool thanks again Sanford!