Set preventDefault back to False on Javascript event

I try to stop the insert event and re-issue it with different data (the if statement is designed to prevent constant re-issuance, ignores it):

@HostListener('paste', ['$event']) onPaste(e) { if (this.doNotReissuePaste) { this.doNotReissuePaste = false; } else { this.reformatPasteText(e); e.preventDefault(); } } 

My goal is to pretend that the first event never happened, because I need Angular2 to handle the field "normally." This part is for context only, the question is, how can I resend the event without the defaultPrevented property being true? I cannot change it because it is read-only and I cannot find documents about creating a new paste event anywhere (that is why I resort to copying it).

  private reformatPasteText(pasteEvent) { this.doNotReissuePaste = true; let pastedText: string = pasteEvent.clipboardData.getData('Text'); let formattedPaste: string = formattingMagicWheeee(pastedText); //pasteEvent.defaultPrevented = false; //Cannot change it this way setTimeout(() => { pasteEvent.clipboardData.setData('text/plain', formattedPaste); this.target.dispatchEvent(pasteEvent); }, 1); } 

PS Ignore the Angular2 part - no need to think about it, it's just a Javascript question about creating / editing Javascript events.

0
source share

Source: https://habr.com/ru/post/1012735/


All Articles