Send the value to the <input> tag following each iteration in the functions

I am currently utilizing BootstrapVue.

In my code, I have implemented a for loop to retrieve unique numbers from an array, which are stored as this.number. For each iteration of the loop, I use input.push() to add a new b-form-input element (in this case, 3 times).

When adding a new b-form-input, I want to display the corresponding unique number from this.number in each input field.

Is there a way to achieve this? Thank you for your help!

Here is a snippet of the template:

<div v-for="(id, index) in inputs" :key="index">
  <b-form-input type="number" v-model="id.number" :value="id.number" @input="searchNumber(id, index)" ></b-form-input>
</div>

And here is part of my script:

methods: {
  inputValue() {
    for (let i = 0; i < 3; i++) {
      this.number= (String(this.data[i].number));
      this.inputs.push({});

      console.log(this.number);
    }
  }
},

data() {
  return {
    inputs: [{}],
  }
},

The result of console.log(this.number) is:

1111
2222
3333

Hence, 1111 should correspond to the v-model/value of b-form-input 0, 2222 should be displayed in v-model/value of b-form-input 1, and 3333 should populate v-model/value of b-form-input 2.

Answer №1

It seems like the goal here is to render 3 input fields and update the second input when a user types in it.

  1. Create 3 input fields
  2. Update input number 2 when user inputs

The code structure can be hard to follow. I recommend creating a function that triggers when an input field emits an input event, passing the index as you have with searchNumber.

<div v-for="(id, index) in inputs" :key="index">
  <b-form-input type="number" :value="id.number" @input="onInput($event, index)" ></b-form-input>
</div>
methods: {
  onInput(input, index) {
    this.inputs[index].number = input;
  }
}

I have replaced v-model with value and @input for clarity.

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

Returning draggable elements to their original placement

I'm looking to create a custom function that resets my draggable elements to their original positions when invoked. This is not related to the built-in revert functionality. $('.drag').draggable({ stack: ".drag", snap: ".dro ...

The app constantly requests permission for geolocation services

While experimenting with the geolocation API, I encountered an issue where my page kept repeatedly asking for permission upon refresh. To work around this problem, I attempted to save my coordinate data to local storage but encountered difficulties in ma ...

The functionality of two-way binding in a distinct controller is not functioning properly when integrated with angular-wizard

I've been working hard to integrate this amazing wizard controller into my project: However, I've hit a roadblock with two-way binding not functioning as expected outside of the <section> attribute: http://plnkr.co/edit/N2lFrBRmRqPkHhUBfn ...

Issue with undefined object in ExpressJS PUT method

Attempting to utilize the PUT method for updating a record in my database, I encountered an issue with the object not being defined. ReferenceError: blogpost is not defined Following this tutorial for routing steps, I noticed that while the variable is d ...

Vue's asynchronous handling of props

I have a method that triggers an asynchronous call. methods: { computeCoveragePercentage() { this.calculateCompletionBySubject(1).then((percent) => { return percent; }); }, This method computes a percentage based o ...

Utilize checkboxes in Vue to refine the list items

I am working on a simple list items and filter panel, you can find the code on CodeSandbox: <template> <div id="filter"> <h1>Filter List</h1> <div class="filter-panel"> <ul class="filter-list"> ...

Tips for sending a string from the state of a React component to an external Python script

My journey into ReactJS and web development is just beginning. I am currently working on a web application where users can input mathematical expressions as strings. Upon submitting the input, I intend to process it using a Python script and display the o ...

Sorry, this route does not support the GET method. Please use the POST method to input data

I have been facing a challenge with the Laravel - Vue input problem that I can't seem to resolve. Following my teacher's tutorial worked perfectly fine, but replicating it on my own led to console errors displaying the following message: `Access ...

Angular login/signup modal/dialog component for seamless user authentication

Currently, I am working on adding a login/signin dialog to my app similar to the one used by Medium. After doing extensive research online, I have decided to use the $modal from angular ui-bootstrap for this. Can anyone please recommend a tutorial that wil ...

Automatically trigger the Submit button click with this selector

I'm having trouble automating the clicking of a 'Submit' button that only becomes clickable after a specific action is taken. In this case, the user needs to click the TOS checkbox before the button can be clicked. I've been unable to f ...

Exploring the possibilities with Node.js and OpenCV

I'm experiencing difficulties with face tracking and detection using the npm opencv package. Right now, I'm attempting to draw a circle around each detected face. Below are the error details and associated files. I'm unsure if it's a b ...

Guide on integrating Troisjs into a Nuxt 3 project

I am interested in incorporating TroisJS (a wrapper for three.js designed for Vue) into my project using Nuxt.js. The TroisJS documentation at suggests adding it to the project like this: import { TroisJSVuePlugin } from 'troisjs'; app.use(Trois ...

Creating new form fields dynamically using JavaScript (triggered by onClick event)

I want to dynamically add fields based on user interaction. For instance, when the checkbox or radio button is clicked, additional fields like buttons and textfields should appear. Is it possible to achieve this using onClick? If so, can you please provide ...

Tips for confirming a sub string is present in an array using JavaScript/TScript

I am currently testing for the presence of a SubString within an array. In my test, I am asserting using: expect(classList).toContain('Rail__focused') However, I encountered the following error: Error: expect(received).toContain(expected // inde ...

Passing Data using Props in Vue 3 and Vue Router Leads to Invalid Parameters Alert

Currently, I am working on a project using Vue 3 and attempting to pass data between views via Vue Router. Specifically, I am aiming to transfer data from JobSelection.vue to Invoice.vue by utilizing router parameters. In my index.js file, I have defined ...

Is it possible to include personalized validations in Formik's YupValidationSchema?

Is it possible to include custom validations in Formik's YupValidationSchema as shown below? YupValidationSchema = () => { return Yup.object({ Email: Yup.string() .max(256, "Length exceed 256 chars") ...

modify an element using jquery

Hey there! I'm facing an issue where I have an ID of #item_quantity in a span, and I want it to refresh its contents once a button with the ID of #update_cart is clicked. It seems that everything else updates fine on click, but for some reason, the sp ...

(RESPOND) Configuring a preset option for a Dropdown selection field

I am currently developing a frontend to demonstrate the behavior of a CRUD RESTful API. One specific requirement is that when the user selects the option "GET", the default value in the dropdown field labeled "Order-by" should be set to "Name". However, fo ...

How to deal with jQuery's set val() behavior on SELECT when there is no matching value

Let's say I have a select box like this: <select id="s" name="s"> <option value="0">-</option> <option value="1">A</option> <option value="2" selected>B</option> <option value="3">C</option> </ ...

Tips for effectively displaying checkboxes in Vuetify autocomplete menu with multiple options and item slots:

Is there a way to show a checkbox in the Vuetify autocomplete menu with multiple options and an item slot? I am using the item slot because I want to add a tooltip on the item, but the checkbox disappears after this. <v-autocomplete v-i ...