From ec2511793a5c68eede35939e72911abcb5ef692b Mon Sep 17 00:00:00 2001 From: jos Date: Tue, 19 Jan 2016 21:52:52 +0100 Subject: [PATCH] Fixed #259: when having a JSONEditor inside an HTML form, clicking an entry in the context menu did submit the form --- HISTORY.md | 2 ++ src/js/ContextMenu.js | 4 +++- test/test_build.html | 4 +++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index fbe7379..ab32e69 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -7,6 +7,8 @@ https://github.com/josdejong/jsoneditor - Improvements in sanitizing invalid JSON. - Fixed clicking format/compact not triggering an onChange event. +- Fixed #259: when having a JSONEditor inside an HTML form, clicking an entry + in the context menu did submit the form. ## 2016-01-16, version 5.1.1 diff --git a/src/js/ContextMenu.js b/src/js/ContextMenu.js index 01c7ff9..412b5c4 100644 --- a/src/js/ContextMenu.js +++ b/src/js/ContextMenu.js @@ -73,6 +73,7 @@ function ContextMenu (items, options) { } if (item.click) { button.onclick = function () { + event.preventDefault(); me.hide(); item.click(); }; @@ -113,7 +114,8 @@ function ContextMenu (items, options) { } // attach a handler to expand/collapse the submenu - buttonSubmenu.onclick = function () { + buttonSubmenu.onclick = function (event) { + event.preventDefault(); me._onExpandItem(domItem); buttonSubmenu.focus(); }; diff --git a/test/test_build.html b/test/test_build.html index 173a54d..728e5af 100644 --- a/test/test_build.html +++ b/test/test_build.html @@ -33,7 +33,9 @@ editor.setMode(mode), try it in the console of your browser.

-
+
+
+