From df12832a6b7432c840f11900f94e67f51116ff07 Mon Sep 17 00:00:00 2001 From: jos Date: Tue, 1 Nov 2016 21:00:21 +0100 Subject: [PATCH] Fixed #85: pressing enter in an input in a form containing a JSONEditor too breaks submitting the form --- HISTORY.md | 5 +++++ src/js/ContextMenu.js | 3 +++ src/js/ModeSwitcher.js | 1 + src/js/Node.js | 4 ++++ src/js/SearchBox.js | 4 ++++ src/js/appendNodeFactory.js | 1 + src/js/textmode.js | 2 ++ src/js/treemode.js | 4 ++++ 8 files changed, 24 insertions(+) diff --git a/HISTORY.md b/HISTORY.md index d7b8392..3bbda1e 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -3,6 +3,11 @@ https://github.com/josdejong/jsoneditor +## not yet released, version 5.5.10 + +- Fixed #85: pressing enter in an input in a form containing a JSONEditor too + breaks submitting the form. + ## 2016-10-17, version 5.5.9 - Fixed #329: Editor showing duplicate key warnings for keys defined on the diff --git a/src/js/ContextMenu.js b/src/js/ContextMenu.js index 338f40a..216a1bc 100644 --- a/src/js/ContextMenu.js +++ b/src/js/ContextMenu.js @@ -42,6 +42,7 @@ function ContextMenu (items, options) { // create a (non-visible) button to set the focus to the menu var focusButton = document.createElement('button'); + focusButton.type = 'button'; dom.focusButton = focusButton; var li = document.createElement('li'); li.style.overflow = 'hidden'; @@ -68,6 +69,7 @@ function ContextMenu (items, options) { // create a button in the menu item var button = document.createElement('button'); + button.type = 'button'; button.className = item.className; domItem.button = button; if (item.title) { @@ -96,6 +98,7 @@ function ContextMenu (items, options) { button.className += ' jsoneditor-default'; var buttonExpand = document.createElement('button'); + buttonExpand.type = 'button'; domItem.buttonExpand = buttonExpand; buttonExpand.className = 'jsoneditor-expand'; buttonExpand.innerHTML = '
'; diff --git a/src/js/ModeSwitcher.js b/src/js/ModeSwitcher.js index 0c99557..77c6c49 100644 --- a/src/js/ModeSwitcher.js +++ b/src/js/ModeSwitcher.js @@ -72,6 +72,7 @@ function ModeSwitcher(container, modes, current, onSwitch) { // create the html element var box = document.createElement('button'); + box.type = 'button'; box.className = 'jsoneditor-modes jsoneditor-separator'; box.innerHTML = currentTitle + ' ▾'; box.title = 'Switch editor mode'; diff --git a/src/js/Node.js b/src/js/Node.js index ad6592b..8a6d0fa 100644 --- a/src/js/Node.js +++ b/src/js/Node.js @@ -164,6 +164,7 @@ Node.prototype.setError = function (error, child) { popover.appendChild(document.createTextNode(error.message)); var button = document.createElement('button'); + button.type = 'button'; button.className = 'jsoneditor-schema-error'; button.appendChild(popover); @@ -1485,6 +1486,7 @@ Node.prototype.getDom = function() { // create draggable area if (this.parent) { var domDrag = document.createElement('button'); + domDrag.type = 'button'; dom.drag = domDrag; domDrag.className = 'jsoneditor-dragarea'; domDrag.title = 'Drag to move this field (Alt+Shift+Arrows)'; @@ -1496,6 +1498,7 @@ Node.prototype.getDom = function() { // create context menu var tdMenu = document.createElement('td'); var menu = document.createElement('button'); + menu.type = 'button'; dom.menu = menu; menu.className = 'jsoneditor-contextmenu'; menu.title = 'Click to open the actions menu (Ctrl+M)'; @@ -2123,6 +2126,7 @@ Node.prototype._createDomValue = function () { Node.prototype._createDomExpandButton = function () { // create expand button var expand = document.createElement('button'); + expand.type = 'button'; if (this._hasChilds()) { expand.className = this.expanded ? 'jsoneditor-expanded' : 'jsoneditor-collapsed'; expand.title = diff --git a/src/js/SearchBox.js b/src/js/SearchBox.js index 43ff961..61ba943 100644 --- a/src/js/SearchBox.js +++ b/src/js/SearchBox.js @@ -52,12 +52,14 @@ function SearchBox (editor, container) { tbodySearch.appendChild(tr); var refreshSearch = document.createElement('button'); + refreshSearch.type = 'button'; refreshSearch.className = 'jsoneditor-refresh'; td = document.createElement('td'); td.appendChild(refreshSearch); tr.appendChild(td); var search = document.createElement('input'); + // search.type = 'button'; this.dom.search = search; search.oninput = function (event) { searchBox._onDelayedSearch(event); @@ -81,6 +83,7 @@ function SearchBox (editor, container) { tr.appendChild(td); var searchNext = document.createElement('button'); + searchNext.type = 'button'; searchNext.title = 'Next result (Enter)'; searchNext.className = 'jsoneditor-next'; searchNext.onclick = function () { @@ -91,6 +94,7 @@ function SearchBox (editor, container) { tr.appendChild(td); var searchPrevious = document.createElement('button'); + searchPrevious.type = 'button'; searchPrevious.title = 'Previous result (Shift+Enter)'; searchPrevious.className = 'jsoneditor-previous'; searchPrevious.onclick = function () { diff --git a/src/js/appendNodeFactory.js b/src/js/appendNodeFactory.js index 12b7466..494dcb6 100644 --- a/src/js/appendNodeFactory.js +++ b/src/js/appendNodeFactory.js @@ -52,6 +52,7 @@ function appendNodeFactory(Node) { var tdMenu = document.createElement('td'); dom.tdMenu = tdMenu; var menu = document.createElement('button'); + menu.type = 'button'; menu.className = 'jsoneditor-contextmenu'; menu.title = 'Click to open the actions menu (Ctrl+M)'; dom.menu = menu; diff --git a/src/js/textmode.js b/src/js/textmode.js index 91a5741..eba801f 100644 --- a/src/js/textmode.js +++ b/src/js/textmode.js @@ -95,6 +95,7 @@ textmode.create = function (container, options) { // create format button var buttonFormat = document.createElement('button'); + buttonFormat.type = 'button'; buttonFormat.className = 'jsoneditor-format'; buttonFormat.title = 'Format JSON data, with proper indentation and line feeds (Ctrl+\\)'; this.menu.appendChild(buttonFormat); @@ -110,6 +111,7 @@ textmode.create = function (container, options) { // create compact button var buttonCompact = document.createElement('button'); + buttonCompact.type = 'button'; buttonCompact.className = 'jsoneditor-compact'; buttonCompact.title = 'Compact JSON data, remove all whitespaces (Ctrl+Shift+\\)'; this.menu.appendChild(buttonCompact); diff --git a/src/js/treemode.js b/src/js/treemode.js index f36cdee..1fc243e 100644 --- a/src/js/treemode.js +++ b/src/js/treemode.js @@ -676,6 +676,7 @@ treemode._createFrame = function () { // create expand all button var expandAll = document.createElement('button'); + expandAll.type = 'button'; expandAll.className = 'jsoneditor-expand-all'; expandAll.title = 'Expand all fields'; expandAll.onclick = function () { @@ -685,6 +686,7 @@ treemode._createFrame = function () { // create expand all button var collapseAll = document.createElement('button'); + collapseAll.type = 'button'; collapseAll.title = 'Collapse all fields'; collapseAll.className = 'jsoneditor-collapse-all'; collapseAll.onclick = function () { @@ -696,6 +698,7 @@ treemode._createFrame = function () { if (this.history) { // create undo button var undo = document.createElement('button'); + undo.type = 'button'; undo.className = 'jsoneditor-undo jsoneditor-separator'; undo.title = 'Undo last action (Ctrl+Z)'; undo.onclick = function () { @@ -706,6 +709,7 @@ treemode._createFrame = function () { // create redo button var redo = document.createElement('button'); + redo.type = 'button'; redo.className = 'jsoneditor-redo'; redo.title = 'Redo (Ctrl+Shift+Z)'; redo.onclick = function () {