What is the best way to set the v-model property to an object that is constantly changing

I'm in the process of creating a dynamic form that allows users to add additional fields by simply clicking on a button labeled "adicionar condição." The concept is similar to what can be seen in the screenshot below: https://i.stack.imgur.com/Mpmr6.png

Each row within this form follows a structured data format, as shown here:

groups: [
  {
    connective: 'and',
    conditions: [
      {
        type: 'lead_prop',
        field: 'tags',
        condition: 'has',
        value: ''
      }
    ]
  }
]

By clicking the "adicionar condição" button, a new object is added to the conditions array, utilizing the following method:

<v-btn @click="addCondition(i)">Adicionar condição</v-btn>

addCondition(index) {
      this.groups[index].conditions.push({
        type: 'lead_prop',
        field: 'tags',
        condition: 'has',
        value: ''
      });
    }

Incorporating Vuetify autocomplete poses a challenge with maintaining unique values. Whenever a new condition object is added to the group's conditions array, it seems like the v-model of the autocomplete component remains consistent. Altering the value of the newly added autocomplete also affects the previous ones, as illustrated here: https://i.stack.imgur.com/9a378.png

If there is a change in the "tags" field, all existing autocompletes receive the same value. This presents an issue with how the autocomplete model is bound:

   <v-autocomplete
    v-model="g.conditions[index].value"
    :items="tags"
    :teste="index"
    :loading="isLoading"
    :search-input.sync="search"
    color="white"
    hide-no-data
    hide-selected
    item-text="tag"
    item-value="id"
    label="Tags"
    placeholder="Comece a digitar para procurar"
    prepend-icon="mdi-tag"
    return-object>

How can I ensure each tags autocomplete field is correctly linked to its respective object within the conditions array?

This is my current approach for iterating through the data:

<v-card v-for="(g, i) in groups" :key="i">
<v-row v-for="(c, index) in g.conditions" :key="index">

Answer №1

A helpful approach is to develop a lightweight component housing the autocomplete feature and then make the model change property accessible.

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

Using JavaScript to display content on the screen

As a newcomer to Javascript, I'm looking for a way to display my variable on the webpage without utilizing <span> or innerHTML. var pProductCode = $('[name=pProductCode]').val(); $('input[id*="_IP/PA_N_"]').each(function(i){ ...

Activate Input by Clicking on Label in Internet Explorer version 8

I am trying to implement a widget in JQuery colorbox that allows users to load files. My approach involves using an input tag with type='file' and styling it with visibility:hidden. Additionally, I have created two labels that are styled like but ...

The function client.guilds.find cannot be located

Hey there! I've been tasked with working on a Discord bot that requires several dependencies to function properly. I've installed the necessary dependencies and attempted to run the bot using 'forever -o out.log bot.js'. However, I enc ...

The React hamburger menu triggers a re-render of child elements within the layout

I am currently working with React and Material UI v5. Within my layout, I have a menu component with children. Whenever I click on the menu, it triggers a refresh of the children components. I attempted to resolve this by encapsulating the child components ...

Removing connected entries with pre middleware on mongoose

I currently have 3 different schemas: Building const BuildingSchema = mongoose.Schema({ address: { type: String, required: true }, numberOfFloors: { type: Number, default: 0 }, }); Apartment const RoomSchema = mongoose.Schema({ roomNumber: { type: ...

Tips on using the $.grep() method in jQuery to filter dynamic inputs

When using the "grep" function in jQuery to filter data, the code sample below works well for static conditions. However, if the "name" and "school" parameters have multiple values, how can we filter them? Let's say I receive the name and school from ...

The function type '(state: State, action: AuthActionsUnion) => State' cannot be assigned to the argument

I have encountered a persistent error in my main.module.ts. The code snippet triggering the error is as follows: @NgModule({ declarations: [ PressComponent, LegalComponent, InviteComponent ], providers: [ AuthService ], imports: ...

Add value to a progress bar over time until it reaches the designated timeout

I'm struggling to implement a loading bar with a fixed timeout requirement. The goal is for the bar to be completely filled within 5 seconds. While I have successfully created the HTML and CSS components, I am facing difficulty in developing the JavaS ...

Angular can be used to compare two arrays and display the matching values in a table

Having two arrays of objects, I attempted to compare them and display the matching values in a table. While looping through both arrays and comparing them by Id, I was able to find three matches. However, when trying to display these values in a table, onl ...

Looping through JQuery change events

I have a challenge with handling checkboxes. Whenever a user checks one, I need to validate if they are permitted to do so. If not, I must notify them and uncheck the box. However, this process becomes recursive as it triggers the change event again! How c ...

Incorporating an Edit button with an icon into a react-bootstrap-table2

Is there a way to insert buttons in the Edit column of my table so I can easily edit a row? I believe there should be a method to personalize the column and incorporate icons as shown in the example image. Sample Image of What I want to do: import React ...

Problem-solving modal disappearance

In my current project, I am working on a feature that involves displaying a dropdown modal after 3 minutes on the page. The modal includes an input field where users can enter digits, and upon clicking 'save', the modal should hide. Everything se ...

What is causing the scripts to fail when I attempt to press a button?

Clicking on the button is supposed to slowly reveal phone numbers on the page. Here are the HTML Codes: <span id="show-phone-numbers" class="btn btn-success"> <i class="fe fe-phone-call"></i> Show Phone Nu ...

Update the text for the filter search placeholder in the Ant Table component

Is there a way to alter the default placeholder text in the Ant Table? I've set up a functioning example in documentation but couldn't find any prop for customization besides the customized filter dropdown, which I didn't want to implement. ...

jQuery and Easy Dialog

My jQuery Model window has a form inside. Even though I have set autoOpen to false in my dialog, the fields are still visible when the page is created. All forms are contained within a div. This is what my dialog code looks like: $("#dialog-form").dial ...

What is the reason for AngularJS not utilizing the most recently assigned value?

<html> <head> <title>Test</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script src="angul ...

Conceal all video containers once a single one is chosen

Having recently delved into Javascript, I am encountering some difficulties in crafting the correct code for a specific function. The scenario involves multiple div elements, each containing 2 child div elements that switch places upon being clicked. Con ...

Filtering data with React's multiselect checkboxes

I have created an amazing app that fetches a list of todos from this incredible source To enhance user experience, I developed a special CheckBoxDropDown component for selecting todo IDs Within the CheckBoxDropDown.js component, I am passing the onChange ...

Unable to switch between states by clicking on a component in Vue

How can I toggle the state when clicking on a specific element? <script> import ArrowSwitcher from '@/components/ui/ArrowSwitcher.vue' export default { components: { ArrowSwitcher }, data () { return { showContent: fal ...

Unique Javascript Library Focused on AJAX

Looking for a specific JavaScript library that focuses solely on AJAX functionality, such as a basic XMLHttp wrapper. ...