diff --git a/addons/web_editor/static/src/js/editor/snippets.editor.js b/addons/web_editor/static/src/js/editor/snippets.editor.js index f2d6a2b40d5..86fadd1709a 100644 --- a/addons/web_editor/static/src/js/editor/snippets.editor.js +++ b/addons/web_editor/static/src/js/editor/snippets.editor.js @@ -1054,6 +1054,7 @@ var SnippetEditor = Widget.extend({ width: self.$target.width(), height: self.$target.height() }; + const closestFormEl = this.$target[0].closest('form'); self.$target.after('
'); self.$target.detach(); self.$el.addClass('d-none'); @@ -1081,6 +1082,16 @@ var SnippetEditor = Widget.extend({ if (this.$target[0].classList.contains('s_table_of_content')) { $selectorChildren = $selectorChildren.filter((i, el) => !el.closest('.s_table_of_content')); } + // Disallow dropping form fields outside of their form. + // TODO this can probably be implemented by reviewing data-drop-near + // definitions in master but we should find a better to define those and + // such cases. + if (this.$target[0].classList.contains('s_website_form_field')) { + $selectorSiblings = $selectorSiblings.filter( + (i, el) => closestFormEl === el.closest('form') + ); + } + const canBeSanitizedUnless = this._canBeSanitizedUnless(this.$target[0]); // Remove the siblings that belong to a snippet in grid mode