From 761ad42290f09f2e6aa962e453e3483d0aaf13ab Mon Sep 17 00:00:00 2001 From: asajjad2 Date: Mon, 29 Sep 2025 16:00:24 +0500 Subject: [PATCH 1/2] fix: prevent errant body string on title edit --- .../js/discussion/views/discussion_thread_edit_view.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/common/static/common/js/discussion/views/discussion_thread_edit_view.js b/common/static/common/js/discussion/views/discussion_thread_edit_view.js index ca1c2043e3..29378548ab 100644 --- a/common/static/common/js/discussion/views/discussion_thread_edit_view.js +++ b/common/static/common/js/discussion/views/discussion_thread_edit_view.js @@ -7,7 +7,10 @@ tagName: 'form', events: { submit: 'updateHandler', - 'click .post-cancel': 'cancelHandler' + 'click .post-cancel': 'cancelHandler', + 'keypress input:not(.wmd-input)': function(event) { + return DiscussionUtil.ignoreEnterKey(event); + } }, attributes: { From 0b020a4bf4ed73e72ea97179e56a4538b115ec76 Mon Sep 17 00:00:00 2001 From: asajjad2 Date: Fri, 10 Oct 2025 12:17:29 +0500 Subject: [PATCH 2/2] test: edit form errant behavior --- .../view/discussion_thread_edit_view_spec.js | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/common/static/common/js/spec/discussion/view/discussion_thread_edit_view_spec.js b/common/static/common/js/spec/discussion/view/discussion_thread_edit_view_spec.js index 5dbd02b11d..1aa7b1f4ed 100644 --- a/common/static/common/js/spec/discussion/view/discussion_thread_edit_view_spec.js +++ b/common/static/common/js/spec/discussion/view/discussion_thread_edit_view_spec.js @@ -93,6 +93,49 @@ testCancel(this.view); }); + describe('Enter key behavior in title input', function() { + beforeEach(function() { + this.createEditView(); + this.titleInput = this.view.$('.edit-post-title'); + }); + + it('prevents form submission when Enter is pressed in title input', function() { + var submitSpy = jasmine.createSpy('submitSpy'); + this.view.$el.on('submit', submitSpy); + + var enterKeyEvent = $.Event('keypress', {which: 13, keyCode: 13}); + this.titleInput.trigger(enterKeyEvent); + expect(submitSpy).not.toHaveBeenCalled(); + }); + + it('prevents default behavior when Enter is pressed in title input', function() { + var enterKeyEvent = $.Event('keypress', {which: 13, keyCode: 13}); + var preventDefaultSpy = spyOn(enterKeyEvent, 'preventDefault'); + + this.titleInput.trigger(enterKeyEvent); + expect(preventDefaultSpy).toHaveBeenCalled(); + }); + + it('does not prevent non-Enter key presses in title input', function() { + var submitSpy = jasmine.createSpy('submitSpy'); + this.view.$el.on('submit', submitSpy); + + var aKeyEvent = $.Event('keypress', {which: 65, keyCode: 65}); + var preventDefaultSpy = spyOn(aKeyEvent, 'preventDefault'); + this.titleInput.trigger(aKeyEvent); + expect(preventDefaultSpy).not.toHaveBeenCalled(); + }); + + it('does not interfere with body editor when Enter is pressed', function() { + var bodyEditor = this.view.$('.edit-post-body textarea'); + var enterKeyEvent = $.Event('keypress', {which: 13, keyCode: 13}); + var preventDefaultSpy = spyOn(enterKeyEvent, 'preventDefault'); + + bodyEditor.trigger(enterKeyEvent); + expect(preventDefaultSpy).not.toHaveBeenCalled(); + }); + }); + describe('renderComments', function() { beforeEach(function() { this.course_settings = new DiscussionCourseSettings({