I am trying to get values that I type using an on-screen keyboard into a custom HTML element input field to display.
However I am currently getting empty strings. If I use a normal input field then it works fine.
Here is a snippet of my code and a stackblitz example which will have detailed code.
HTML
<form-input
appOskInput
[formStatus]="formStatus"
[parentFormGroup]="setupForm"
[data]="{
formControlName: 'email',
name: 'email'
}">
</form-input>
<app-keyboard></app-keyboard>
Keyboard directive
private onKey(key: string) {
let element = this.el.nativeElement;
let inputEl = element.querySelector('input');
let start = inputEl.selectionStart;
let end = inputEl.selectionEnd;
this.measure.textContent = inputEl.value.substr(0, start) + key;
inputEl.value = inputEl.value.substr(0, start) + key + inputEl.value.substr(end);
if (this.control)
this.control.control.setValue(inputEl.value)
inputEl.focus();
inputEl.selectionStart = inputEl.selectionEnd = start + 1;
this.updateScrollPosition();
}
Here is the stackblitz https://stackblitz.com/edit/onscreen-keyboard-hlmkvv?file=src/app/app.component.ts
You will see that the values are displaying when inputted from a normal input field but I can't get the same to happen when using my custom HTML element input field. I have commented out the custom HTML input field in the code on the HTML page. Can anyone help please?