I am trying to stop a paste event and re-issue it with different data (the if statement is for preventing constant re-issuing, ignore it):
@HostListener('paste', ['$event']) onPaste(e) {
if (this.doNotReissuePaste) {
this.doNotReissuePaste = false;
} else {
this.reformatPasteText(e);
e.preventDefault();
}
}
My goal is to pretend the first event never happened, because I need Angular2 to process the field "normally". This part is just for context, the question is how do I re-issue the event without the defaultPrevented
property being true? I can't change it because it's read only, and I can't find docs on creating a brand new paste event anywhere (which 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);
}
P.S. Ignore the Angular2 part - no need to think about it, this is purely a Javascript question on creating/editing Javascript events.