Concentrate on input fields within Vuetify's expansion panels

Struggling to achieve input focus inside v-expansion-panels upon hitting enter? While I've successfully made the next expansion panel open and accessed the input via the $refs API, I'm unable to make the input focus. Check out a snippet of my code below:

<v-expansion-panels v-model="openedPanel" :accordion="true">
              <v-expansion-panel class="panel">
                <!-- Unidade Produtiva -->
                <v-expansion-panel-header>Unidade produtiva</v-expansion-panel-header>
                <v-expansion-panel-content eager>
                  <label class="panel-label">Número do Talhão</label>

                  <v-container>
                    <v-row>
                      <v-col class="spacing-container" cols="12" md="12">
                        <ValidationProvider name="production-field" rules="required">
                          <input
                            ref="field"
                            v-on:keyup.enter="$refs.height.focus"
                            class="default-input"
                            v-model="production.field"
                            type="number"
                            placeholder="Ex.: 1"
                          />
                        </ValidationProvider>
                      </v-col>
                    </v-row>
                  </v-container>
                  <label class="panel-label">Tamanho do Canteiro</label>
                  <v-container>
                    <v-row>
                      <v-col class="spacing-container" cols="12" md="6">
                        <label class="input-label">Comprimento (m)</label>
                        <ValidationProvider name="production-height" rules="required">
                          <input
                            ref="height"
                            v-on:keyup.enter="$refs.width.focus"
                            class="default-input"
                            v-model="production.height"
                            type="number"
                            step="0.001"
                            min="0.001"
                            placeholder="Ex.: 1.23"
                          />
                        </ValidationProvider>
                      </v-col>
                      <v-col class="spacing-container" cols="12" md="6">
                        <label class="input-label">Largura (m)</label>
                        <ValidationProvider name="production-width" rules="required">
                          <input
                            ref="width"
                            v-on:keyup.enter="$refs.spacew.focus"
                            class="default-input"
                            v-model="production.width"
                            type="number"
                            step="0.001"
                            min="0.001"
                            placeholder="Ex.: 1.23"
                          />
                        </ValidationProvider>
                      </v-col>
                    </v-row>
                  </v-container>
                  <label class="panel-label">Espaçamento</label>
                  <v-container>
                    <v-row>
                      <v-col class="spacing-container" cols="12" md="6">
                        <label class="input-label">Entre linhas (cm)</label>
                        <ValidationProvider name="production-spacew" rules="required">
                          <input
                            ref="spacew"
                            v-on:keyup.enter="$refs.spaceh.focus"
                            class="default-input"
                            v-model="production.spacew"
                            type="number"
                            step="0.001"
                            min="0.001"
                            placeholder="Ex.: 1.23"
                          />
                        </ValidationProvider>
                      </v-col>
                      <v-col class="spacing-container" cols="12" md="6">
                        <label class="input-label">Entre colunas (cm)</label>
                        <ValidationProvider name="production-spaceh" rules="required">
                          <input
                            ref="spaceh"
                            v-on:keyup.enter="handleNext(1, 'name')"
                            class="default-input"
                            v-model="production.spaceh"
                            type="number"
                            step="0.001"
                            min="0.001"
                            placeholder="Ex.: 1.23"
                          />
                        </ValidationProvider>
                      </v-col>
                    </v-row>
                  </v-container>
                </v-expansion-panel-content>
              </v-expansion-panel>
              <v-expansion-panel class="panel">
                <!-- Nome do produto -->
                <v-expansion-panel-header>Nome do produto</v-expansion-panel-header>
                <v-expansion-panel-content eager>
                  <label class="panel-label">Nome</label>
                  <ValidationProvider name="production-name" rules="required">
                    <input
                      ref="name"
                      v-on:keyup.enter="handleNext(2, 'bed')"
                      class="default-input"
                      v-model="production.name"
                      type="text"
                      placeholder="Ex.: Macaxeira"
                    />
                  </ValidationProvider>
                </v-expansion-panel-content>
              </v-expansion-panel>
            </v-expansion-panels>

Snippet of methods being utilized:

openPanel(index) {
      this.openedPanel = index;
    },
    closeAllPanels() {
      this.openedPanel = null;
    },
    handleNext(index, refInput) {
      this.closeAllPanels();
      this.openPanel(index);
      this.$refs[refInput].focus();
      console.log(refInput);
      console.log(this.$refs[refInput]);
    },

Note: Edited "focus" to "focus()", though it remains unresolved.

Answer №1

To ensure that the

<v-expansion-panel-content>
completes its transition before proceeding, it is recommended to utilize the setTimeout function.

For instance:

...
  navigateToNextPanel(index, inputRef) {
    if (this.activePanel === index) {
      this.$refs[inputRef].focus();
    } else {
      this.openPanel(index);
      setTimeout(() => {
        this.$refs[inputRef].focus();
      }, 350); // vuetify default transition duration: 300ms
    }
  }
...

View Example on JSFiddle

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Use JavaScript to dynamically generate a drop-down select menu

Is there a way to automatically expand a select menu dropdown using JavaScript or jQuery when a button is clicked? I am facing this challenge because I have a text field that allows users to input custom fields dynamically into a select input. My goal is ...

Is it possible to manipulate angularjs data without using a controller?

In my main webpage, there are just two sections: a navigation bar and the changing content. index.html: <div ng-controller='MainCtrl'> <li ng-repeat="nav in navs"> <a href="#{{nav.url}}">{{nav.name}}</a> ...

Creating dynamic names for radio buttons in Bootstrap forms: A guide to generating unique identifiers

This is a continuation of the discussion in this post. To better understand the concept, refer to this JSfiddle example. Check out the final solution provided by @Scaramouche The challenge at hand involves dynamically generating unique names for radio b ...

Use jQuery to easily add and remove rows from a table dynamically

Is there a way to dynamically add rows to an HTML table using jQuery by utilizing a popup window? The popup would contain text fields, checkboxes, radio buttons, and an "add" button. Upon clicking the "add" button, a new row would be added to the table. ...

Organizing requirejs and angularjs code structure into separate files

Looking to organize my Angular application with requirejs by separating controllers, services, and directives into different files. Hoping to achieve this structure: src/ components/ Navigation/ index.js module.js NavigationCon ...

"Converting Text from a Streamed XML-Like File into CSV: A Step-by-Step Guide

I have log files that contain C++ namespace artifacts (indicated by the double colons ::) and XML content embedded within them. After loading and displaying the logs in a browser application, the content has been separated from the Unix timestamps like so: ...

Attempting to toggle variable to true upon click, but encountering unexpected behavior

On my webpage, I have implemented a simple tab system that is only displayed when the variable disable_function is set to false. However, I am facing an issue with setting disable_function to true at the end of the page using a trigger. When this trigger ...

JavaScript ES6 array method for generating an object from an array

I wish to transform the following array: [ { event: "LIB", block_calendar: "YES", obs: "Lorem Ipsum", status: "Block", }, { event: "LIB" block_calendar: "YES" o ...

What steps should be taken to retrieve the contents of a file that has been chosen using the browse

You have successfully implemented a browse button that allows the user to navigate the directory and choose a file. The path and file name are then displayed in the text element of the Browse button complex. Now, the question arises - how can I extract dat ...

A guide on updating an item in a basic JavaScript file with Node.js

This query pertains to Workbox and Webpack, but no prior knowledge of these libraries is necessary. Background Information (Optional) Currently using the InjectManifest plugin from Workbox 4.3.1 (workbox-webpack-plugin). While this version provides the o ...

JavaScript code altered link to redirect to previous link

I added a date field to my HTML form. <input type="date" name="match_date" id="matchDate" onchange="filterMatchByDate(event)" min="2021-01-01" max="2021-12-31"> There is also an anchor tag ...

Why isn't my textarea in jQUERY updating as I type?

On my website, I have a comment script that is not functioning correctly in some parts of the jQuery/JavaScript code. Instead of posting an edited comment to PHP, I created a notification window to test if the value passed through is actually changing. W ...

Are the styles in app.scss going to waste with Laravel and Vue?

I'm currently working on a Laravel and Vue project using the Frontend Scaffolding outlined in the documentation found here: https://laravel.com/docs/7.x/frontend $ composer require laravel/ui $ php artisan ui vue Once executed, this command will load ...

"Utilizing AngularJS event system through $broadcast and $on

I have recently started learning AngularJS and I am trying to send a message from one controller to another. I have looked at various examples and my code seems to be similar, but it is not working. Why is $rootScope.$on not working? Can anyone help me wit ...

Is there an equivalent of numpy.random.choice in JavaScript?

The Numpy.random.choice function is a handy tool that allows you to select a sample of integers based on a specific probability distribution: >>> np.random.choice(5, 3, p=[0.1, 0, 0.3, 0.6, 0]) array([3, 3, 0]) Is there a similar feature in Java ...

Date parsing error thrown by jQuery datepicker plugin

What could be causing the InvalidDate exception when attempting to parse the date using $.datepicker.parseDate("mm/yy","02/2008");? ...

Utilize Jquery to toggle text input forms based on radio button selections

I have a group of text inputs labeled with the class 'bankinput'. Alongside them, I have two radio buttons generated by asp.net helpers. The ids assigned to these radio buttons in the generated html are 'Cheque' and 'Draft'. F ...

Creating a conditional property in TypeScript based on an existing type - a comprehensive guide

Imagine if I had the following: type Link = { text: string; link: string; } interface BigLink extends Link { some: number; something: string; else: string; } However, there's a variable that shares all these properties except for the fact ...

KineticJs: Enhancing Rotation with Multitouch Capability

Currently, I have a click event implemented in my code that rotates my puzzle piece by 90 degrees when clicked. However, I would like to change it from a mouse click to a touch event. How can I achieve this? Thank you. piecesArray[i][j].shape.on("mous ...

Having trouble displaying the accurate model value in the alert

I have the following piece of code: $(document).ready(function () { var edit= @Model.Edit.ToString().ToLower(); if( edit !=true ) { $("#editWriteup").hide(); } var date= @Model.EndDate; alert(date); ...