Prevent comments from submitting after input as composition ends
This commit is contained in:
parent
430abe8743
commit
bc1fc50780
|
@ -1,7 +1,7 @@
|
||||||
import registerEvents from "retrospring/utilities/registerEvents"
|
import registerEvents from "retrospring/utilities/registerEvents"
|
||||||
import { commentCharacterCountHandler } from "./count";
|
import { commentCharacterCountHandler } from "./count";
|
||||||
import { commentDestroyHandler } from "./destroy";
|
import { commentDestroyHandler } from "./destroy";
|
||||||
import { commentCreateHandler } from "./new";
|
import {commentComposeEnd, commentComposeStart, commentCreateHandler} from "./new";
|
||||||
import { commentReportHandler } from "./report";
|
import { commentReportHandler } from "./report";
|
||||||
import { commentSmileHandler } from "./smile";
|
import { commentSmileHandler } from "./smile";
|
||||||
import { commentToggleHandler } from "./toggle";
|
import { commentToggleHandler } from "./toggle";
|
||||||
|
@ -12,6 +12,8 @@ export default (): void => {
|
||||||
{ type: 'click', target: '[name=ab-smile-comment]', handler: commentSmileHandler, global: true },
|
{ type: 'click', target: '[name=ab-smile-comment]', handler: commentSmileHandler, global: true },
|
||||||
{ type: 'click', target: '[data-action=ab-comment-report]', handler: commentReportHandler, global: true },
|
{ type: 'click', target: '[data-action=ab-comment-report]', handler: commentReportHandler, global: true },
|
||||||
{ type: 'click', target: '[data-action=ab-comment-destroy]', handler: commentDestroyHandler, global: true },
|
{ type: 'click', target: '[data-action=ab-comment-destroy]', handler: commentDestroyHandler, global: true },
|
||||||
|
{ type: 'compositionstart', target: '[name=ab-comment-new]', handler: commentComposeStart, global: true },
|
||||||
|
{ type: 'compositionend', target: '[name=ab-comment-new]', handler: commentComposeEnd, global: true },
|
||||||
{ type: 'keyup', target: '[name=ab-comment-new]', handler: commentCreateHandler, global: true },
|
{ type: 'keyup', target: '[name=ab-comment-new]', handler: commentCreateHandler, global: true },
|
||||||
{ type: 'input', target: '[name=ab-comment-new]', handler: commentCharacterCountHandler, global: true }
|
{ type: 'input', target: '[name=ab-comment-new]', handler: commentCharacterCountHandler, global: true }
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -3,7 +3,14 @@ import { post } from '@rails/request.js';
|
||||||
import I18n from 'retrospring/i18n';
|
import I18n from 'retrospring/i18n';
|
||||||
import { showNotification, showErrorNotification } from 'utilities/notifications';
|
import { showNotification, showErrorNotification } from 'utilities/notifications';
|
||||||
|
|
||||||
|
let compositionJustEnded = false;
|
||||||
|
|
||||||
export function commentCreateHandler(event: KeyboardEvent): boolean {
|
export function commentCreateHandler(event: KeyboardEvent): boolean {
|
||||||
|
if (compositionJustEnded && event.which == 13) {
|
||||||
|
compositionJustEnded = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const input = event.target as HTMLInputElement;
|
const input = event.target as HTMLInputElement;
|
||||||
const id = input.dataset.aId;
|
const id = input.dataset.aId;
|
||||||
const counter = document.querySelector(`#ab-comment-charcount-${id}`);
|
const counter = document.querySelector(`#ab-comment-charcount-${id}`);
|
||||||
|
@ -51,3 +58,13 @@ export function commentCreateHandler(event: KeyboardEvent): boolean {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function commentComposeStart(): boolean {
|
||||||
|
compositionJustEnded = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function commentComposeEnd(): boolean {
|
||||||
|
compositionJustEnded = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue