Guide on submitting a pre-filled form with data pulled from an array of objects using vue

My current school project involves creating a web app for dog walkers. I am currently working on a form to update the information of dogs owned by a user.

This data is stored in an array of objects, where each object represents a dog's information. I am using a v-for loop to iterate through the array and display a form for each dog. Below is the code snippet for the initial component:

<template>
  <div class="body">
    <h1 class="mt-3">Your Dogs</h1>
    <b-row class="mt-1">
      <div class="cards mx-5 mb-5">
        <UpdatePets 
          v-for="pet in pets"
          :key="pet.id"
          :pet="pet"
          :currentUser="currentUser"
          :title="pet.dog_name"
          tag="article"
          style="max-width: 17rem;"
          class="card">
        </UpdatePets>
        </div>
    </b-row>
  </div>
</template>

... (continued with remaining script and style elements)

The form does not prefill with the information as expected. The issue seems to lie in the UpdatePets component. Here's the code for that component:

<template>
  <div class="body">
    <b-row class="mt-1">
      <div class="cards mx-5 mb-5">
         <b-form @submit.prevent="updateMascota" class="pl-4">
            ... (form inputs omitted for brevity)
           </b-form>
      </div>
    </b-row>
  </div>
</template>

... (continued with remaining script and style elements)

I have also included a working example of updating a user's information successfully. The code snippet for that component is provided below:

<template>
  <div class="home">
    <div class="body">
      <h1>Update User Information</h1>
    <div class="SignUp">
      ... (form inputs and submit button omitted for brevity)
      </div>
      </div>
    </div>
</template>

... (continued with remaining script and style elements)

If you can offer any guidance on why the form is not prefilling or provide insights based on the Vue Devtools screenshot shared here, it would be greatly appreciated. Thank you!

Answer №1

  1. Ensure that in UpdatePets.vue, the props pets and currentUser are declared only once in data()
  2. In the main .vue file, make sure to pass the prop as pet instead of pets to match what is accepted in UpdatePets.vue

Aside from these adjustments, everything should function correctly. You can view a simple demo I created here: https://codesandbox.io/s/priceless-elbakyan-ef2qu?file=/src/App.vue

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

Turn off HTML display for Internet Explorer users

I am looking to implement code that will block certain pages for Internet Explorer users, making it accessible only for Google Chrome and Firefox users. Do you have any suggestions on how I can achieve this or if there are existing solutions available? I& ...

Following the build in Angular, it only displays the index.html file and a blank screen

According to the information on Angular's official website, running the "ng build" command should generate files in the dist folder ready for hosting. However, after running this command, the index.html file is empty except for the page title. When yo ...

Images are failing to load in Ionic 3

Currently working on developing an Ionic application and troubleshooting the use of the camera native plugin. The script functions flawlessly in a fresh project, but encounters issues within the current project environment. Initially suspected a problem w ...

Utilizing jQuery to close a modal when clicking outside of its container

Trying to target elements in my practice layout but struggling to figure out the right approach: BASIC HTML <button id="opencontact" type="button" name="button"> <i class="far fa-envelope fa-2x"></i> </button> <section id="c ...

Sending a file stream with specific file name and extension in NodeJS: A comprehensive guide

Currently, I am utilizing nodejs to transmit file streams to express response var fileReadStream = fs.createReadStream(filePath); fileReadStream.pipe(res); However, the issue arises on the front-end where the file is solely downloadable with the "download ...

Refresh in AJAX, automated loading for seamless transition to a different page

Having an issue with the page not auto-refreshing, although it loads when I manually refresh. P.S Loading the page onto another page. Below is my HTML and AJAX code along with its database: The Trigger Button <?php $data = mysqli_query ...

Unable to get Custom Fonts to display in PDFMake for Vue

Trying to convert HTML to PDF using PDFMake and htmlToPdfMake in a Vue Project. While PDFMake only supports Roboto by default, I wanted to add custom fonts. So, I added the Font Files (.ttf) to ./examples/fonts in the PDFMake folder inside ./node_modules. ...

React code to automatically scroll to the top of the page when the user clicks the

Whenever the URL changes or the page is reloaded in my project, I need it to scroll back to the top. While most scenarios work fine, I'm encountering an issue with the browser's back button. Despite a change in the pathname, the page fails to scr ...

Retrieve the HTML content of all children except for a specific child element in jQuery

Is there a way to utilize jQuery/Javascript for selecting the HTML content of the two <p> elements in the initial <div class="description? I'm open to using Regex as well. This specific jQuery selection is being executed within Node.js on a c ...

Strategies for incorporating a string into an ng-template using HTML

Suppose I have an ng-template as follows: <ng-template #templateRef> <button (click)="testClick()" Click me </button> <a I'm a link </a> </ng-template> Now, I want to utilize it in my html template li ...

Setting up event listeners from a string array (using PIXI.js)

Hey there! I've encountered a bit of an interesting challenge that could easily be resolved by duplicating the code, but where's the fun in that? This project is more of an experiment for me, just to prove that I can do it. However, the idea has ...

In the Swiper function of JavaScript within a Django template, the occurrence of duplicate elements (products) is being generated

Experimenting with displaying products in a Django template, I decided to utilize the Swiper js class. This allowed me to showcase the products within a div, complete with navigation buttons for scrolling horizontally. However, when testing this setup wit ...

What could be the reason for my jQuery script not functioning properly?

<script> var currentLevel = 0; $(document).ready(function(){ $("#tolevel_" + (currentLevel+1) ).click(function(){ $("#level_" + currentLevel).hide(500,'swing', function(){ $("#level ...

Possible issue with accurate indexing causing caption error with API images in React

Continuing from: Implementing a lightbox feature in react-multi-carousel for my ReactJS app My application utilizes react-images for the lightbox functionality and react-carousel-images for the carousel. The API provides a title and image data. The issue ...

Tips for restricting the information retrieved from an API?

Currently, I am in the process of learning how to use AJAX with vanilla JS. My goal is to implement a limit on the amount of data received from an API, specifically restricting it to 10 objects maximum. The API url that I am working with can be found here ...

Instantly summing up two numbers with javascript

In my web development work using Visual Studio 2008, I encountered an interesting challenge. On a webpage, I have three textboxes labeled "Price," "Quantity," and "Amount." The task at hand is to calculate the value of "Amount" by multiplying the values ...

The socket.io client in my JavaScript code is failing to receive the necessary event

Currently, I am in the process of configuring a socket.io chat feature with an expressjs backend and sveltejs frontend. I have established a custom namespace named 'chat' where a new room is generated upon a 'join' request. My appro ...

Why isn't the close button in jQuery working on an Asp.net page?

My current project involves working with Asp.net and C#. I am facing an issue where I click on a button to display a message in a popup box, but when I try to close the popup by clicking the close button, it does not close. Here is the syntax for the aspx ...

Is it possible to override the body width setting?

Is it possible to override the width of the body element? For example, consider the following: <body> <table id="table1"> <tr><td></td></tr> </table> <table id="table2"> <tr><td></td>& ...

Tips for implementing a dynamic tag using AngularJS

I am attempting to use AngularJS to create an HTML element to facilitate downloading a file from the server to the client. I have found that the most straightforward method is to utilize an HTML element with the href attribute. Here is the code snippet I a ...