select text of input fields when focused

- the content of input fields of relevant sheets and dialogs
  are now selected upon focus
- autofocus the Gamemaster roll modifier in the roll dialog
This commit is contained in:
Gesina Schwalbe 2021-01-24 13:11:08 +01:00
parent a8158894dd
commit 0b1c342ecf
2 changed files with 19 additions and 1 deletions

View file

@ -133,3 +133,21 @@ Hooks.once("setup", function () {
Hooks.once("ready", function () { Hooks.once("ready", function () {
migration.migrate(); migration.migrate();
}); });
/**
* Select the text of input elements in given sheets via onfocus listener.
* The hook names are of the form "render"+sheet_superclassname and are called within
* the render() method of the foundry Application class.
* Note: The render hooks of all classes in the class hierarchy are called,
* so e.g. for a Dialog, both "renderDialog" and "renderApplication" are called
* (in this order).
*/
["renderApplication", "renderActorSheet", "renderItemSheet"].forEach((hookName: string) => {
Hooks.on(hookName, (app: Dialog, html: JQueryStatic, data: any) => {
$(html)
.find("input")
.on("focus", (ev: JQuery.FocusEvent<HTMLInputElement>) => {
ev.currentTarget.select();
});
});
});

View file

@ -2,7 +2,7 @@
<label for="ctv">{{localize "DS4.RollDialogTargetLabel"}}</label> <label for="ctv">{{localize "DS4.RollDialogTargetLabel"}}</label>
<input id="ctv" data-type="Number" type="number" name="ctv" value="{{checkTargetValue}}" /> <input id="ctv" data-type="Number" type="number" name="ctv" value="{{checkTargetValue}}" />
<label for="gmmod">{{localize "DS4.RollDialogModifierLabel"}}</label> <label for="gmmod">{{localize "DS4.RollDialogModifierLabel"}}</label>
<input id="gmmod" data-type="Number" type="number" name="gmmod" value="0" /> <input id="gmmod" data-type="Number" type="number" name="gmmod" value="0" autofocus />
<label for="maxcoup">{{localize "DS4.RollDialogCoupLabel"}}</label> <label for="maxcoup">{{localize "DS4.RollDialogCoupLabel"}}</label>
<input id="maxcoup" data-type="Number" type="number" name="maxcoup" value="{{maxCritSuccess}}" /> <input id="maxcoup" data-type="Number" type="number" name="maxcoup" value="{{maxCritSuccess}}" />
<label for="minfumble">{{localize "DS4.RollDialogFumbleLabel"}}</label> <label for="minfumble">{{localize "DS4.RollDialogFumbleLabel"}}</label>