1
votes

Unfortunately, the Apps Script documentation page about DataValidation builder is missing information about the requireCheckbox method.

When you type it in via a script file, though, autocompletion offers 3 overloads:

no args:

requireCheckbox()

1 arg:

requireCheckbox(Object checkedValue)

2 args:

requireCheckbox(Object checkedValue, Object uncheckedValue)

What parameters of an object can I use in these arguments and what purposes they may serve?

2

2 Answers

6
votes

CHECKBOX cell by default, has two values:

  • TRUE, when checked and
  • FALSE when unchecked.

Depending on the number of arguments provided to requireCheckbox, different values are used:

  • No argument:
    • The default values are used.
  • One argument:
    • The provided argument, when checked
    • Blank, when unchecked
  • Two arguments:
    • The provided arguments are used for checked and unchecked states respectively.

Sample code:

function yesNoDV() {
  //Changes checked state to 'Yes'  and Unchecked state to 'No'
  SpreadsheetApp.getActive()
    .getRange('Sheet1!A1')
    .setDataValidation(
      SpreadsheetApp.newDataValidation()
        .requireCheckbox('Yes', 'No')
        .build()
    );
}
0
votes

Object is the default type Google's documentation uses when more specific types do not apply. You can safely interpret it as an analog for any (and in fact, the @types TypeScript package for Google Apps Script has those parameters annotated with any).

Also, as of 2021, the documentation has information on all method overloads. To quote from it, the overloads function is as follows.

No arguments

Sets the data validation rule to require that the input is a boolean value; this value is rendered as a checkbox.

One argument

Sets the data validation rule to require that the input is the specified value or blank. When the input matches the specified value the cell is rendered as a checked checkbox. When the input is blank the cell is rendered as an unchecked checkbox.

Two arguments

Sets the data validation rule to require that the input is one of the specified values. When the input is checkedValue the cell is rendered as a checked checkbox. When the input is uncheckedValue the cell is rendered as an unchecked checkbox.

The meaning of each overload hasn't changed from that outlined in TheMaster's answer.