{"record":{"id":"b49a6346d8d05419","repo":"framework7io/framework7","slug":"framework7-texteditor-wrong-buttons-parameter","errorCode":null,"errorMessage":"Framework7: TextEditor: wrong \"buttons\" parameter format","messagePattern":"Framework7: TextEditor: wrong \"buttons\" parameter format","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/core/components/text-editor/text-editor-class.js","lineNumber":74,"sourceCode":"      $contentEl = $el.children('.text-editor-content');\n    }\n\n    extend(self, { app, $el, el: $el[0], $contentEl, contentEl: $contentEl[0] });\n    if ('value' in params) {\n      self.value = self.params.value;\n    }\n\n    if (self.params.mode === 'keyboard-toolbar') {\n      if (!(device.cordova || device.capacitor) && !device.android) {\n        self.params.mode = 'popover';\n      }\n    }\n\n    if (typeof self.params.buttons === 'string') {\n      try {\n        self.params.buttons = JSON.parse(self.params.buttons);\n      } catch (err) {\n        throw new Error('Framework7: TextEditor: wrong \"buttons\" parameter format');\n      }\n    }\n\n    $el[0].f7TextEditor = self;\n\n    // Bind\n    self.onButtonClick = self.onButtonClick.bind(self);\n    self.onFocus = self.onFocus.bind(self);\n    self.onBlur = self.onBlur.bind(self);\n    self.onInput = self.onInput.bind(self);\n    self.onPaste = self.onPaste.bind(self);\n    self.onSelectionChange = self.onSelectionChange.bind(self);\n    self.closeKeyboardToolbar = self.closeKeyboardToolbar.bind(self);\n\n    // Handle Events\n    self.attachEvents = function attachEvents() {\n      if (self.params.mode === 'toolbar') {\n        self.$el.find('.text-editor-toolbar').on('click', 'button', self.onButtonClick);","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/framework7io/framework7/blob/655759126686766530a027b2f8f369c991d63d1c/src/core/components/text-editor/text-editor-class.js#L56-L92","documentation":"The TextEditor `buttons` parameter must be an array (or array of arrays) of button names/objects. If it is passed as a string, the constructor attempts JSON.parse to coerce it; when parsing fails it throws, because a non-JSON string cannot be interpreted as a buttons config.","triggerScenarios":"Passing `buttons: 'bold, italic, underline'` or any comma-separated / malformed string in the TextEditor params; strings from HTML `data-buttons` attributes that are not valid JSON.","commonSituations":"Configuring the editor via data attributes where the string is not JSON; copying a JS array config into a string; typos like single quotes in JSON (`{'bold':'bold'}`) which JSON.parse rejects.","solutions":["Pass buttons as an actual JS array: buttons: ['bold', 'italic', 'underline']","If a string must be used, make it valid JSON: '[\"bold\",\"italic\"]' (double quotes, no trailing commas)","Check any data-buttons attribute for strict JSON syntax"],"exampleFix":"// before\nnew Framework7.TextEditor({ el: '#editor', buttons: 'bold,italic' });\n\n// after\nnew Framework7.TextEditor({ el: '#editor', buttons: ['bold', 'italic'] });","handlingStrategy":"validation","validationCode":"function parseButtons(buttons) {\n  if (typeof buttons === 'string') {\n    try { return JSON.parse(buttons); } catch (e) { return null; }\n  }\n  return buttons;\n}\nconst buttons = parseButtons(rawButtons);\nif (!buttons) throw new Error('buttons must be an array or valid JSON');","typeGuard":"function isValidButtons(v) {\n  return Array.isArray(v) && v.every(b => typeof b === 'string' || typeof b === 'object');\n}","tryCatchPattern":"try {\n  const editor = new Framework7.TextEditor({ el, buttons: rawButtons });\n} catch (e) {\n  if (/wrong \"buttons\" parameter format/.test(e.message)) {\n    console.error('buttons must be an array or valid JSON string');\n  } else throw e;\n}","preventionTips":["Always pass buttons as a JS array, not a string","If using data-* attributes, validate the JSON before init","Use double quotes and no trailing commas in JSON strings","Unit-test editor config parsing"],"tags":["configuration","json","text-editor","framework7"],"backgroundTag":"invalid-config-format","analyzedSha":"655759126686766530a027b2f8f369c991d63d1c","analyzedAt":"2026-09-02T19:48:40.711Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}