dianping/cat · error · Error

prompt with checkbox requires options

Error message

prompt with checkbox requires options

What it means

For prompt dialogs with inputType 'checkbox' (and the older 'radio'), bootbox requires a non-empty options.inputOptions array and throws this error when it is missing or empty — the checkbox list would otherwise render with nothing to check. It mirrors the select-type check at error 77, followed by the same wrong-format validation of the first entry.

Source

Thrown at cat-home/src/main/webapp/assets/js/uncompressed/bootbox.js:506

          }

          elem.append("<option value='" + option.value + "'>" + option.text + "</option>");
        });

        each(groups, function(_, group) {
          input.append(group);
        });

        // safe to set a select's value as per a normal input
        input.val(options.value);
        break;

      case "checkbox":
        var values   = $.isArray(options.value) ? options.value : [options.value];
        inputOptions = options.inputOptions || [];

        if (!inputOptions.length) {
          throw new Error("prompt with checkbox requires options");
        }

        if (!inputOptions[0].value || !inputOptions[0].text) {
          throw new Error("given options in wrong format");
        }

        // checkboxes have to nest within a containing element, so
        // they break the rules a bit and we end up re-assigning
        // our 'input' element to this container instead
        input = $("<div/>");

        each(inputOptions, function(_, option) {
          var checkbox = $(templates.inputs[options.inputType]);

          checkbox.find("input").attr("value", option.value);
          checkbox.find("label").append(option.text);

          // we've ensured values is an array so we can always iterate over it

View on GitHub (pinned to e815e74d4c)

Solutions

  1. Only open the prompt when the list is non-empty; otherwise alert or skip: if (!tags.length) return bootbox.alert('No tags available.');
  2. Await the data source before constructing the dialog.
  3. If a single yes/no checkbox is wanted, use inputType 'checkbox' with one explicit option or a plain confirm() instead.

Example fix

// before
bootbox.prompt({ title: 'Select tags', inputType: 'checkbox', callback: saveTags }); // no inputOptions

// after
if (!tags.length) { bootbox.alert('No tags available.'); return; }
bootbox.prompt({
  title: 'Select tags', inputType: 'checkbox',
  inputOptions: tags.map(function (t) { return { value: t.id, text: t.label }; }),
  callback: saveTags
});
Defensive patterns

Strategy: validation

Validate before calling

if (!Array.isArray(items) || !items.length) {
  bootbox.alert('No options available.');
  return;
}
bootbox.prompt({ title: 'Select', inputType: 'checkbox',
  inputOptions: items.map(function (i) { return { value: i.id, text: i.label }; }),
  callback: cb });

Type guard

function hasNonEmptyCheckboxOptions(o) {
  return Array.isArray(o.inputOptions) && o.inputOptions.length > 0 &&
    o.inputOptions[0].value !== undefined && o.inputOptions[0].text !== undefined;
}

Prevention

When it happens

Trigger: bootbox.prompt({title: 'Pick tags', inputType: 'checkbox', callback: fn}) with no inputOptions; inputOptions: [] because the tags/permissions list loaded asynchronously and was still empty; passing the data under options/items instead of inputOptions.

Common situations: Building multi-select checkbox prompts from server data that can legitimately be empty (no tags yet); race between an AJAX fetch and opening the dialog; assuming checkbox prompts need no options because a bare checkbox would suffice.

Related errors


AI-assisted analysis of dianping/cat@e815e74d4c (2026-08-14). Data as JSON: /api/errors/d5fdd2cc186aabf1. Report an issue: GitHub.