Set focus to element with autofocus attribute

This commit is contained in:
Bartek Fabiszewski 2020-05-22 23:17:02 +02:00
parent 7169abc60f
commit ee5c70ee5a
4 changed files with 16 additions and 5 deletions

View File

@ -64,6 +64,17 @@ export default class uDialog {
if (!this.visible) {
document.body.append(this.element);
this.visible = true;
this.autofocus();
}
}
/**
* Set focus to element with autofocus attribute
*/
autofocus() {
const focusEl = this.element.querySelector('[autofocus]');
if (focusEl) {
focusEl.focus();
}
}

View File

@ -64,7 +64,7 @@ export default class PositionDialogModel extends ViewModel {
<div style="clear: both; padding-bottom: 1em;"></div>
<form id="positionForm">
<label><b>${$._('comment')}</b></label><br>
<textarea style="width:100%;" maxlength="255" rows="5" placeholder="${$._('comment')}" name="comment" data-bind="comment">${this.position.hasComment() ? uUtils.htmlEncode(this.position.comment) : ''}</textarea>
<textarea style="width:100%;" maxlength="255" rows="5" placeholder="${$._('comment')}" name="comment" data-bind="comment" autofocus>${this.position.hasComment() ? uUtils.htmlEncode(this.position.comment) : ''}</textarea>
<div class="buttons">
<button class="button-reject" data-bind="onCancel" type="button">${$._('cancel')}</button>
<button class="button-resolve" data-bind="onPositionUpdate" type="submit">${$._('submit')}</button>

View File

@ -58,7 +58,7 @@ export default class TrackDialogModel extends ViewModel {
<div style="clear: both; padding-bottom: 1em;"></div>
<form id="trackForm">
<label><b>${$._('trackname')}</b></label>
<input type="text" placeholder="${$._('trackname')}" name="trackname" data-bind="trackname" value="${uUtils.htmlEncode(this.track.name)}" required>
<input type="text" placeholder="${$._('trackname')}" name="trackname" data-bind="trackname" value="${uUtils.htmlEncode(this.track.name)}" required autofocus>
<div class="buttons">
<button class="button-reject" data-bind="onCancel" type="button">${$._('cancel')}</button>
<button class="button-resolve" data-bind="onTrackUpdate" type="submit">${$._('submit')}</button>

View File

@ -157,7 +157,7 @@ export default class UserDialogModel extends ViewModel {
case 'add':
observer = 'onUserAdd';
header = `<label><b>${$._('username')}</b></label>
<input type="text" placeholder="${$._('usernameenter')}" name="login" data-bind="login" required>`;
<input type="text" placeholder="${$._('usernameenter')}" name="login" data-bind="login" required autofocus>`;
fields = `<label><b>${$._('password')}</b></label>
<input type="password" placeholder="${$._('passwordenter')}" name="password" data-bind="password" required>
<label><b>${$._('passwordrepeat')}</b></label>
@ -174,7 +174,7 @@ export default class UserDialogModel extends ViewModel {
<input type="checkbox" name="changepass" data-bind="passVisibility"><br>
<div style="display: none;" data-bind="passInput">
<label><b>${$._('password')}</b></label>
<input type="password" placeholder="${$._('passwordenter')}" name="password" data-bind="password" required>
<input type="password" placeholder="${$._('passwordenter')}" name="password" data-bind="password" required autofocus>
<label><b>${$._('passwordrepeat')}</b></label>
<input type="password" placeholder="${$._('passwordenter')}" name="password2" data-bind="password2" required>
</div>
@ -184,7 +184,7 @@ export default class UserDialogModel extends ViewModel {
case 'pass':
observer = 'onPassChange';
fields = `<label><b>${$._('oldpassword')}</b></label>
<input type="password" placeholder="${$._('passwordenter')}" name="old-password" data-bind="oldPassword" required>
<input type="password" placeholder="${$._('passwordenter')}" name="old-password" data-bind="oldPassword" required autofocus>
<label><b>${$._('newpassword')}</b></label>
<input type="password" placeholder="${$._('passwordenter')}" name="password" data-bind="password" required>
<label><b>${$._('newpasswordrepeat')}</b></label>