{"record":{"id":"b1a1e0f96501c0c2","repo":"dianping/cat","slug":"prompt-with-select-requires-options","errorCode":null,"errorMessage":"prompt with select requires options","messagePattern":"prompt with select requires options","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"cat-home/src/main/webapp/assets/js/uncompressed/bootbox.js","lineNumber":466,"sourceCode":"    input = $(templates.inputs[options.inputType]);\n\n    switch (options.inputType) {\n      case \"text\":\n      case \"textarea\":\n      case \"email\":\n      case \"date\":\n      case \"time\":\n      case \"number\":\n      case \"password\":\n        input.val(options.value);\n        break;\n\n      case \"select\":\n        var groups = {};\n        inputOptions = options.inputOptions || [];\n\n        if (!inputOptions.length) {\n          throw new Error(\"prompt with select requires options\");\n        }\n\n        each(inputOptions, function(_, option) {\n\n          // assume the element to attach to is the input...\n          var elem = input;\n\n          if (option.value === undefined || option.text === undefined) {\n            throw new Error(\"given options in wrong format\");\n          }\n\n\n          // ... but override that element if this option sits in a group\n\n          if (option.group) {\n            // initialise group if necessary\n            if (!groups[option.group]) {\n              groups[option.group] = $(\"<optgroup/>\").attr(\"label\", option.group);","sourceCodeStart":448,"sourceCodeEnd":484,"githubUrl":"https://github.com/dianping/cat/blob/e815e74d4c2dd74edac831241f1253fcc7d25381/cat-home/src/main/webapp/assets/js/uncompressed/bootbox.js#L448-L484","documentation":"For prompt dialogs with inputType 'select', bootbox builds <option> elements from options.inputOptions and throws if that array is missing or empty — a select with no options would render a dead control, so it fails fast. inputOptions defaults to [] when absent, which also trips this check.","triggerScenarios":"bootbox.prompt({title: 'Choose', inputType: 'select', callback: fn}) with no inputOptions; inputOptions: [] because the data source (AJAX list, query results) returned nothing or had not loaded yet; inputOptions passed under a wrong property name (options, values).","commonSituations":"Feeding inputOptions from an async source and calling prompt before the data arrives; filtering a list that legitimately becomes empty; misspelling the property so the default [] is used.","solutions":["Guard before calling: only open the prompt when the list has entries — if (!items.length) { bootbox.alert('Nothing to choose from.'); return; }","Load the options first (AJAX/promise), then build the prompt in the completion handler.","Verify the property name is exactly inputOptions and each entry has both value and text (see the follow-on format error)."],"exampleFix":"// before\nbootbox.prompt({ title: 'Assign owner', inputType: 'select', callback: assign }); // inputOptions forgotten\n\n// after\nbootbox.prompt({\n  title: 'Assign owner', inputType: 'select',\n  inputOptions: owners.map(function (o) { return { value: o.id, text: o.name }; }),\n  callback: assign\n});","handlingStrategy":"validation","validationCode":"if (!Array.isArray(items) || !items.length) {\n  bootbox.alert('Nothing to choose from.');\n  return;\n}\nbootbox.prompt({ title: title, inputType: 'select',\n  inputOptions: items.map(function (i) { return { value: i.id, text: i.name }; }),\n  callback: cb });","typeGuard":"function hasNonEmptyInputOptions(o) {\n  return Array.isArray(o.inputOptions) && o.inputOptions.length > 0;\n}","tryCatchPattern":null,"preventionTips":["Load option data before opening the prompt","Property name must be exactly inputOptions","Handle the legitimately-empty-list case with an alert instead"],"tags":["bootbox","prompt","select","input-options","empty-collection"],"backgroundTag":null,"analyzedSha":"e815e74d4c2dd74edac831241f1253fcc7d25381","analyzedAt":"2026-08-14T14:22:34.512Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}