Check All Checkboxes

Contents

Overview

This article introduces how to check all options in Kintone's Checkbox field with one click.

Sample Image

In this example, checking an option in a Checkbox field will check all options in a different Checkbox field.

Sample Code

Prepare the following JavaScript code in a text editor and navigate to the Kintone App's settings.
Upload the file into the JavaScript and CSS Customization settings (External link) .

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
// Check/uncheck all checkbox choices

(function() {
  'use strict';

  var CHECKALL = 'check_all'; // Field code of checkbox to check/uncheck all checkboxes
  var CHECKBOX = 'mycheckbox'; // Field code of checkbox to have all choices checked/unchecked

  var events = ['app.record.create.change.' + CHECKALL, 'app.record.edit.change.' + CHECKALL];

  kintone.events.on(events, function(event) {
    var record = event.record;
    var changes = event.changes.field.value;

    if (changes[0] === 'check all') {
      record[CHECKBOX].value = ['sample1', 'sample2', 'sample3', 'sample4', 'sample5'];
    } else {
      record[CHECKBOX].value = [];
    }
    return event;
  });
}());