In my form, I have two input fields. My goal is to take the text from the first field, replace the first part with different text, and dynamically populate it into the second field. While I have managed to retrieve the value from the first field easily, I am struggling to figure out how to replace and snip the text on keyup. Below is the code snippet: Component HTML
<div class="labels">Real Name</div>
<div class="lbl">
<input #realName type="text" [(ngModel)]="actualName" (keyup)="trigger()">
</div>
<div class="labels">Cyber Name</div>
<div class="lbl">
<input #cybName type="text"[(ngModel)]="cyberName">
</div>
Component TS
@ViewChild('realName') realName: ElementRef;
@ViewChild('cybName') cybName: ElementRef;
trigger() {
this.cybName.nativeElement.value = this.realName.nativeElement.value;
}
Currently, I am simply setting the cyber name to be the same as the real name on every keyup event. However, I actually want to snip the first 4 characters of the real name and replace them with "droid", while keeping the rest of the characters intact. For example, if the real name entered is "Alexys", the desired output should be "droidys".
I understand that handling this on keyup might not be the best approach. I would appreciate any suggestions or assistance in implementing this functionality. Thank you.