Trying to auto-focus on the next input field after 1 character is typed.
Getting error: Property '$refs' does not exist on type 'void'.
Here is the function:
setup() {
const autoFocusNextInput = (event, max: number) => {
if (event.target.value.length === max) {
const nextElement =
this.$refs[`input-${Number(event.target.dataset.index) + 1}`];
if (nextElement) nextElement.focus();
}
};
Here is the template for context:
<div class="d-flex flex-wrap justify-content-between">
<Field
class=
type="text"
name="1"
maxlength="1"
ref="input-0"
data-index="0"
@input="autoFocusNextInput($event, 1)"
autocomplete="off"
/>
<Field
class=
type="text"
name="2"
maxlength="1"
ref="input-1"
data-index="1"
@input="autoFocusNextInput($event, 1)"
autocomplete="off"
/>