{"record":{"id":"d5fdd2cc186aabf1","repo":"dianping/cat","slug":"prompt-with-checkbox-requires-options","errorCode":null,"errorMessage":"prompt with checkbox requires options","messagePattern":"prompt with checkbox requires options","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"cat-home/src/main/webapp/assets/js/uncompressed/bootbox.js","lineNumber":506,"sourceCode":"          }\n\n          elem.append(\"<option value='\" + option.value + \"'>\" + option.text + \"</option>\");\n        });\n\n        each(groups, function(_, group) {\n          input.append(group);\n        });\n\n        // safe to set a select's value as per a normal input\n        input.val(options.value);\n        break;\n\n      case \"checkbox\":\n        var values   = $.isArray(options.value) ? options.value : [options.value];\n        inputOptions = options.inputOptions || [];\n\n        if (!inputOptions.length) {\n          throw new Error(\"prompt with checkbox requires options\");\n        }\n\n        if (!inputOptions[0].value || !inputOptions[0].text) {\n          throw new Error(\"given options in wrong format\");\n        }\n\n        // checkboxes have to nest within a containing element, so\n        // they break the rules a bit and we end up re-assigning\n        // our 'input' element to this container instead\n        input = $(\"<div/>\");\n\n        each(inputOptions, function(_, option) {\n          var checkbox = $(templates.inputs[options.inputType]);\n\n          checkbox.find(\"input\").attr(\"value\", option.value);\n          checkbox.find(\"label\").append(option.text);\n\n          // we've ensured values is an array so we can always iterate over it","sourceCodeStart":488,"sourceCodeEnd":524,"githubUrl":"https://github.com/dianping/cat/blob/e815e74d4c2dd74edac831241f1253fcc7d25381/cat-home/src/main/webapp/assets/js/uncompressed/bootbox.js#L488-L524","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Only open the prompt when the list is non-empty; otherwise alert or skip: if (!tags.length) return bootbox.alert('No tags available.');","Await the data source before constructing the dialog.","If a single yes/no checkbox is wanted, use inputType 'checkbox' with one explicit option or a plain confirm() instead."],"exampleFix":"// before\nbootbox.prompt({ title: 'Select tags', inputType: 'checkbox', callback: saveTags }); // no inputOptions\n\n// after\nif (!tags.length) { bootbox.alert('No tags available.'); return; }\nbootbox.prompt({\n  title: 'Select tags', inputType: 'checkbox',\n  inputOptions: tags.map(function (t) { return { value: t.id, text: t.label }; }),\n  callback: saveTags\n});","handlingStrategy":"validation","validationCode":"if (!Array.isArray(items) || !items.length) {\n  bootbox.alert('No options available.');\n  return;\n}\nbootbox.prompt({ title: 'Select', inputType: 'checkbox',\n  inputOptions: items.map(function (i) { return { value: i.id, text: i.label }; }),\n  callback: cb });","typeGuard":"function hasNonEmptyCheckboxOptions(o) {\n  return Array.isArray(o.inputOptions) && o.inputOptions.length > 0 &&\n    o.inputOptions[0].value !== undefined && o.inputOptions[0].text !== undefined;\n}","tryCatchPattern":null,"preventionTips":["Await async data before building checkbox prompts","Use confirm() for a single yes/no instead of a one-item checkbox","Each checkbox option needs value and text"],"tags":["bootbox","prompt","checkbox","input-options","empty-collection"],"backgroundTag":null,"analyzedSha":"e815e74d4c2dd74edac831241f1253fcc7d25381","analyzedAt":"2026-08-14T14:22:34.512Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}