Place focus on error block on page reload
This commit is contained in:
parent
fbb7bd7989
commit
8ca1f82b01
2 changed files with 7 additions and 4 deletions
|
@ -2,8 +2,10 @@ import { Controller } from '@hotwired/stimulus';
|
|||
|
||||
export class AutofocusController extends Controller {
|
||||
connect() {
|
||||
const element = this.element as HTMLInputElement;
|
||||
const element = this.element as HTMLInputElement | HTMLElement;
|
||||
element.focus();
|
||||
element.setSelectionRange(0, element.value.length);
|
||||
if ('value' in element) {
|
||||
element.setSelectionRange(0, element.value.length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue