Can you reproduce using one of our samples or online demos?
Yes
Are you using the WebViewer server?
Yes
Does the issue only happen on certain browsers?
No
Is your issue related to a front-end framework?
No
Is your issue related to annotations?
Yes
Tested in our Web-Application and with the online demo.
When entering a Textfield on Windows (or general Desktop) via Tab, the whole Text in the Textfield is selected, on iOS the cursor is placed at the end of the text.
But even if it would work, i would still have the problem, that i don’t know when to call this function, because ther is no onEnter-Event for the form field?!
i tried the solution and it works, but i needed a few small adjustments.
I “casted” the innerElement as HTMLInputElement, otherwise the angular compiler won’t compile it (or throws an error at runtime) because of onfocus isn’t available.
For my needs i also registered a onclick/onkeydown-Event to differntiate between Select via Click or Tab (for this to work a small timeout is needed, because onclick/onkeydown is fired before onfocus)
The whole code is executed within a function which is called when the annotationsLoaded-Event is fired. This function is also called after a small timeout, because otherwise sometimes the innerElement of the annotation-Element was empty.
The function itself:
/**
* Setzt bei allen Formularfeldern ein Fokus-Event, damit beim Sprung per Tab
* in das Formularfeld der Text markiert wird
*/
private setOnFocusEvent(): void {
// Alle Objekte durchlaufen
this.webviewer.instance.Core.annotationManager.getAnnotationsList().forEach((annot) => {
if (annot instanceof this.webviewer.instance.Core.Annotations.TextWidgetAnnotation) {
// In ein HTMLInputElement "casten"
const input = annot.innerElement as HTMLInputElement;
// Falls das Element vorhanden ist/gecastet werden konnte
if (input !== null) {
// Falls per Klick selektiert wird
// -> Text soll nicht selektiert werden
input.onclick = () => {
this._selectAllText = false;
};
// Falls per Tabulator selektiert wird
// -> Text soll selektiert werden
input.onkeydown = () => {
this._selectAllText = true;
};
// Wenn das Element den Fokus erhaelt evtl. den Text selektieren
input.onfocus = () => {
// In einem Timeout, da onclick/onkeydown vor onfocus ausgefuehrt wird
setTimeout(() => {
// Falls noetig Text selektieren
if (this._selectAllText === true) input.select();
// Flag zuruecksetzen
this._selectAllText = false;
}, 100);
};
}
}
});
}
Calling the Function within annotationsLoaded-Event
this.webviewer.instance.Core.documentViewer.addEventListener('annotationsLoaded', () => {
// Nach einem Timeout die Events setzen
// (damit auch alle Felder schon das innerElement haben)
setTimeout(() => {
this.setOnFocusEvent();
}, 500);
}