[BUG] Fix Ctrl+Enter on submitting review comment
- Backport of #2370
- When a event is caused by `Ctrl+Enter` jQuery might not wrap the event
and in that case `originalEvent` is not defined. Check for this case.
- Log the error along with showing an toast.
- Resolves #2363
(cherry picked from commit f04589defd
)
This commit is contained in:
parent
8283305d53
commit
1c3a31d851
1 changed files with 5 additions and 2 deletions
|
@ -57,8 +57,10 @@ function initRepoDiffConversationForm() {
|
||||||
$form.addClass('is-loading');
|
$form.addClass('is-loading');
|
||||||
const formData = new FormData($form[0]);
|
const formData = new FormData($form[0]);
|
||||||
|
|
||||||
// if the form is submitted by a button, append the button's name and value to the form data
|
// If the form is submitted by a button, append the button's name and value to the form data.
|
||||||
const submitter = submitEventSubmitter(e.originalEvent);
|
// originalEvent can be undefined, such as an event that's caused by Ctrl+Enter, in that case
|
||||||
|
// sent the event itself.
|
||||||
|
const submitter = submitEventSubmitter(e.originalEvent ?? e);
|
||||||
const isSubmittedByButton = (submitter?.nodeName === 'BUTTON') || (submitter?.nodeName === 'INPUT' && submitter.type === 'submit');
|
const isSubmittedByButton = (submitter?.nodeName === 'BUTTON') || (submitter?.nodeName === 'INPUT' && submitter.type === 'submit');
|
||||||
if (isSubmittedByButton && submitter.name) {
|
if (isSubmittedByButton && submitter.name) {
|
||||||
formData.append(submitter.name, submitter.value);
|
formData.append(submitter.name, submitter.value);
|
||||||
|
@ -76,6 +78,7 @@ function initRepoDiffConversationForm() {
|
||||||
$newConversationHolder.find('.dropdown').dropdown();
|
$newConversationHolder.find('.dropdown').dropdown();
|
||||||
initCompReactionSelector($newConversationHolder);
|
initCompReactionSelector($newConversationHolder);
|
||||||
} catch { // here the caught error might be a jQuery AJAX error (thrown by await $.post), which is not good to use for error message handling
|
} catch { // here the caught error might be a jQuery AJAX error (thrown by await $.post), which is not good to use for error message handling
|
||||||
|
console.error('error when submitting conversation', e);
|
||||||
showErrorToast(i18n.network_error);
|
showErrorToast(i18n.network_error);
|
||||||
} finally {
|
} finally {
|
||||||
$form.removeClass('is-loading');
|
$form.removeClass('is-loading');
|
||||||
|
|
Loading…
Add table
Reference in a new issue