Is there a way for me to retrieve the data inputted by the user in these v-text-fields within VueJS?

My array, reducedGroups, has been restructured in response to Java's comment below. It is now an Array of Objects with varying numbers of objects inside.

It may have a structure like this:

[ 
{ "0": { "value": "ccc" }, "1": { "value": "aaa" }, "2": { "value": "ddd" }, "3": { "value": "bbb" } }, 
{ "0": { "value": "eeee" } }, 
{ "0": { "value": "fff" } }, 
{ "0": { "value": "ggg" } } 
]

The following code organizes the internal arrays into groups and displays a Vuetify Text Field above for user to name each group.

<div v-for="(group, index) in reducedGroups" :key="index">
    <v-flex>
      <v-text-field label="Group Name" />
      <div
        v-for="item in group"
        :key="item.value"
      >{{ item.value}}</div>
      <div>
      <v-btn icon color="error" @click="removeGroup(index)">
        <v-icon>mdi-trash-can</v-icon>
      </v-btn>
      </div>
   </v-flex>
</div>

The resulting output can be seen below.

https://i.sstatic.net/PvenL.png

I have 2 questions:

1) How do I determine when the user has named each group so that the trash cans can appear on screen?

2) How can I access the names given by the user for the remaining groups once irrelevant ones are removed and only 3 groups remain? I want to display these remaining group names on the screen.

UPDATE: Data restructuring done in response to Java's feedback.

Answer №1

It appears that your data structure may not be suitable for the model, even after refactoring into objects. It seems like you actually have an array of groups. Each group consists of a name (initially empty) and an array of values. If this is correct, a more appropriate data structure would look something like this:

[ 
  { name: "", values: ["ccc", "aaa", "ddd", "bbb"] }, 
  { name: "", values: ["eeee"] }, 
  { name: "", values: ["fff"] }, 
  { name: "", values: ["ggg"] } 
]

With this revised structure, the template becomes simpler to understand. Assuming <v-text-field /> functions similarly to a standard <textarea />:

<div v-for="(group, index) in reducedGroups" :key="index">
    <v-flex>
      <v-text-field label="Group Name" v-model="group.name"/>
      <div
        v-for="value in group.values"
        :key="value"
      >{{value}}</div>
      <div>
      <v-btn icon color="error" @click="removeGroup(index)">
        <v-icon>mdi-trash-can</v-icon>
      </v-btn>
      </div>
   </v-flex>
</div>

Additional Note

To address the feedback received, consider using computed properties to extract names and detect any empty ones:

computed: {
    groupNames() {
        return reducedGroups.map(group => group.name);
    },
    allNamesPresent() {
        return reducedGroups.every(group => group.name);
    }
}

I also recommend exploring a beginner Vue tutorial online for further guidance.

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

Populating divs in an HTML layout using information retrieved from a database

Imagine having an HTML template that looks like this: <template id="template"> <div class="fname"></div> <div class="lname"></div> </template> Now, let's use jQuery/JavaScript to display multiple versions ...

Guide to contrasting elements within a nested object

I am trying to extract data from an auto-generated object by cleaning up duplicates and concatenating any additional entries. Here is a simplified example: const categories = [{ category: "mammal", options: ["horse", "cow" ...

Delete a particular instance of a component from an array within the parent component when a button is clicked within the child component, depending on a specific condition in Angular

One scenario I am facing involves the removal of a component instance from an array (located in the parent component) when a button is clicked inside the child component, based on a specific condition. https://i.sstatic.net/YPFHx.png Within the parent co ...

Sending data from a PHP array to a JavaScript array

I'm currently working on retrieving my SQL query array, converting it into a JavaScript array, and then displaying the information one by one. Despite finding some helpful posts on this topic, I am still struggling to make it work. As a newcomer to aj ...

What is the proper method for transforming an Excel column containing JSON format data into a JavaScript object?

I am facing an issue with converting data from an excel sheet to json format. While the other columns convert successfully, one specific column containing json data is not being converted properly and instead gets treated as a string. Using JSON.parse() on ...

Switch between individual highcharts by selecting or deselecting checkboxes

One of the challenges I am facing involves manipulating multiple scatter plots created with highcharts. I have a list of checkboxes, each labeled to correspond with legend identifiers in the highcharts. My goal is to create a dynamic functionality so tha ...

When I click on my div, the color does not change as expected

Recently, I wrote a code snippet where there are 9 different div elements each assigned a ".spaces" class. The intention was to change the color of these divs upon clicking on them. However, I encountered an issue where only the first div changes its color ...

When a frameset is clicked on

Apologies for my limited English skills, as I am a novice in JavaScript. Seeking assistance! I currently have a website with a frameset consisting of left, top, and main sections. My goal is to incorporate a chat feature with a user list in the left frame ...

After the page has finished loading, I aim to have the modal window pop up after 10 seconds. Thank you to all!

$(document).ready(function() { var id = "#dialog"; //Calculate screen dimensions var maskHeight = $(document).height(); var maskWidth = $(window).width(); //Adjust mask to cover entire screen $('#mask').css({'wid ...

Tips for verifying if the input in a Material UI textfield is an <iframe> tag

In my ReactJS code, I am utilizing the TextField component from material-ui. I need to verify if the user input is an iframe. How can I achieve this? Currently, I am attempting to use window.parent.frames.length > 0; to determine if the page contains a ...

Vuetify Container with a set maximum width that remains fixed

I recently started developing a web application using Vue.js and Vuetify (https://vuetifyjs.com/en/). Currently, I have a basic layout with 3 columns. However, I noticed that the width of these columns is restricted to a maximum of 960px due to some defau ...

React Router Blank Page Conundrum

In a new project, I'm experiencing an issue where the content is not loading in despite using a similar React-Route setup that worked in a previous project. When I create a nav link in the root directory, it changes the path but the screen remains whi ...

Reinitializing AngularJS form controls

Check out this codepen example: http://codepen.io/anon/pen/EjKqbW I'm trying to reset the form elements when the user clicks on "Reset". The div elements f1,f2,f3 should be hidden and the searchText box cleared. However, the reset button is not trig ...

Arranging objects in clusters of 7 and 8 using javascript

Programming: const fs = require("fs"); const { parse } = require("csv-parse"); function fetchSchedule() { let scheduleData = []; fs.createReadStream("./timetable.csv") .pipe(parse({ delimiter: ",", ...

JavaScript conversion of arrays to JSON data structures

Here is the code snippet along with the variable 'polygon': var directionsDisplay; var directionsService = new google.maps.DirectionsService(); var map; var bermudaTriangle; var directionsPoints; var example; var rez; function initialize() { ...

Unveiling the mystery of extracting information from a string post serialization

When working with a form, I am using this jQuery code to fetch all the field values: var adtitletoshow = $("#form_data").serialize(); After alerting adtitletoshow, it displays something like this - &fomdata1=textone&fomdata2=texttwo&fomdat ...

Submit function causes mutation in React form state

My current project involves learning React on my own and creating a small single-page React app using an Axios API. I'm facing a persistent issue with a POST request that keeps failing. After extensively using console.log, it appears that the form inp ...

Error in Vue: Expected object but received a function instead of a valid value

I am attempting to apply a computed function to my style. However, the computed function uses a property within it and Vue is throwing an error stating that it expects an object but is receiving a function. Below is the code in question. <template> ...

Guide to deploying a complete Wordpress application within a Nuxt application

Is it feasible to integrate a complete WordPress application into a Nuxt app? Specifically, I want my app's address to be foo.com, with the WordPress app accessible at foo.com/bar. Can this be achieved, and will the Nuxt router be able to manage this ...

Top technique for verifying the presence of duplicates within an array of objects

How can I efficiently check for duplicates in typescript within a large array of objects and return true or false based on the results? let testArray: { id: number, name: string }[] = [ { "id": 0, "name": "name1" }, ...