Re: "Select all checkbox option?

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
Anonymous
Not applicable

Re: "Select all checkbox option?

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

SanfordWhiteman
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

Anonymous
Not applicable

Re: "Select all checkbox option?

Very cool thanks again Sanford!