{"record":{"id":"d20bd5a3540e6835","repo":"dianping/cat","slug":"button-key-key-is-not-allowed-options-are-butt","errorCode":null,"errorMessage":"button key {key} is not allowed (options are {buttons})","messagePattern":"button key (.+?) is not allowed \\(options are (.+?)\\)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"cat-home/src/main/webapp/assets/js/uncompressed/bootbox.js","lineNumber":294,"sourceCode":"      var value = argument.toUpperCase();\n\n      buttons[key] = {\n        label: _t(value)\n      };\n    }\n\n    return buttons;\n  }\n\n  function validateButtons(options, buttons) {\n    var allowedButtons = {};\n    each(buttons, function(key, value) {\n      allowedButtons[value] = true;\n    });\n\n    each(options.buttons, function(key) {\n      if (allowedButtons[key] === undefined) {\n        throw new Error(\"button key \" + key + \" is not allowed (options are \" + buttons.join(\"\\n\") + \")\");\n      }\n    });\n\n    return options;\n  }\n\n  exports.alert = function() {\n    var options;\n\n    options = mergeDialogOptions(\"alert\", [\"ok\"], [\"message\", \"callback\"], arguments);\n\n    if (options.callback && !$.isFunction(options.callback)) {\n      throw new Error(\"alert requires callback property to be a function when provided\");\n    }\n\n    /**\n     * overrides\n     */","sourceCodeStart":276,"sourceCodeEnd":312,"githubUrl":"https://github.com/dianping/cat/blob/e815e74d4c2dd74edac831241f1253fcc7d25381/cat-home/src/main/webapp/assets/js/uncompressed/bootbox.js#L276-L312","documentation":"Each bootbox dialog type restricts which button keys are allowed (alert: 'ok'; confirm: 'confirm'/'cancel'; prompt adds input-related handling). validateButtons builds the allowed set from the type's button list and throws if options.buttons contains any other key, listing the permitted keys in the message.","triggerScenarios":"bootbox.confirm('Save?', {buttons: {yes: {...}, no: {...}}}) — 'yes'/'no' are not valid for confirm; customizing an alert with a key other than 'ok'; supplying a dialog-style buttons map ({success/danger/primary from the dialog defaults}) to alert/confirm/prompt.","commonSituations":"Assuming all dialog types share the same button vocabulary as bootbox.dialog; copying a dialog() options block into a confirm() call; renaming button keys for readability without realizing the keys are structural identifiers, not labels.","solutions":["Use the type's canonical keys: alert → ok; confirm → confirm and cancel; override labels via the label property, not by renaming keys.","For fully custom buttons, call bootbox.dialog() instead of the typed wrappers.","Keep this bootbox version's key set in mind — allowed keys differ between versions (e.g. some builds map ok/cancel aliases), so pin the version and read its source."],"exampleFix":"// before\nbootbox.confirm('Save changes?', {\n  buttons: { yes: { label: 'Yes' }, no: { label: 'No' } }, callback: save\n});\n\n// after\nbootbox.confirm('Save changes?', function (result) { if (result) save(); });\n// or with custom labels:\nbootbox.confirm({\n  message: 'Save changes?', callback: function (result) { if (result) save(); },\n  buttons: { confirm: { label: 'Yes' }, cancel: { label: 'No' } }\n});","handlingStrategy":"validation","validationCode":"var ALLOWED = { alert: ['ok'], confirm: ['confirm', 'cancel'], prompt: ['confirm', 'cancel'] };\nfunction buttonsAllowedFor(type, buttons) {\n  var ok = ALLOWED[type] || [];\n  return Object.keys(buttons || {}).every(function (k) { return ok.indexOf(k) !== -1; });\n}\nif (!buttonsAllowedFor('confirm', opts.buttons)) useDialogInstead();","typeGuard":"function isAllowedButtonKey(type, key) {\n  var allowed = { alert: ['ok'], confirm: ['confirm', 'cancel'], prompt: ['confirm', 'cancel'] };\n  return (allowed[type] || []).indexOf(key) !== -1;\n}","tryCatchPattern":null,"preventionTips":["Customize labels, not keys, on typed dialogs","Use bootbox.dialog() for arbitrary button sets","Keys are identifiers: ok / confirm / cancel"],"tags":["bootbox","dialog","buttons","validation","api-misuse"],"backgroundTag":null,"analyzedSha":"e815e74d4c2dd74edac831241f1253fcc7d25381","analyzedAt":"2026-08-14T14:22:34.512Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}