Confirm data entry upon modification in a dynamic Vue list

When a value is selected from a drop-down menu in the range of 1-10, the system displays a corresponding number of rows (N = value of dropdown).

Each row represents an object with three properties: x, y, z. All the created rows are stored in an array, resulting in the final data format:

data:{
    rows: [
        {x:0, y:0, z:value},
        .......
        ]
    }

It is necessary to ensure that, for each row, the values of x, y, and z do not exceed 100. If they do, an error should be displayed.

Attempts have been made to achieve this using a function that checks the array on each input change, but this method appears to be inefficient and unreliable.

What is the best way to handle this validation for dynamically generated inputs?

Thank you for your assistance!

Answer №1

Create a listener that monitors any changes in the array:

data:{
    details: [
        {name:"John", age:25, city:"New York"},
        .......
        ]
    },
watch:{
  details:{
        handler(value){
         let isValid=this.details.every(detail=>Object.values(detail).every(val=>val<10))
          if(!isValid){
             //display error message
          }
       },
     deep:true
  }
}

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

What could be causing this code to continuously loop without end?

I've been scratching my head trying to understand why this code isn't working. var refP = []; var calculateDistance = function (p1, p2) { return dist(p1.x, p1.y, p2.x, p2.y); } while (refP.length < 24) { var point = { x: -1, ...

"Easily toggle the visibility of values in checkboxes and organize them into groups with the power of JavaScript

Hey there! I am currently working on a project that involves grouping checkboxes and hiding/unhiding their content based on user interaction. Essentially, when the page first loads, the "All CARS" checkbox will be checked by default. If I then check the "C ...

Navigation that sticks and changes upon hovering over div elements

Just delving into the world of jQuery and JS, so I appreciate your patience:) Currently, I have a sticky navigation bar positioned at the top of my webpage that links to different sections of content below. I am looking to create an effect where the corr ...

Establishing the controller to set the default order

Would appreciate some assistance with what may appear to be a beginner's question, please? This is the HTML code I'm working with: <!doctype html> <html> <head> <title>Starting Angular</title> </head> < ...

Exploring the interplay between jQuery functions and the "Class" method in Javascript

Is there a way to reference a parent "class" method in Javascript from a jQuery function? Here's an example scenario: $Object.prototype.TestFunction = function(arg){ alert(arg); } $Object.prototype.foo = function(){ $(something).click(function ...

Utilizing node.js for manipulating files (JSON) through reading and writing operations

There is an issue with my function that reads a JSON file and updates it using the fs.writeFile method. When I invoke this function multiple times, it fails to update the file properly. After the first call, it adds extra curly brackets at the end of the J ...

The Vue 2 watch feature may encounter difficulties with mixin data properties, however, it functions properly when the data property belongs to the

I recently attempted to refactor some code by moving certain functionalities to a vue mixin from the component itself, with the intention of reusing it in multiple components. The simplified version of the code looks like this: export default { data() { ...

Incorporate relationships while inserting data using Sequelize

vegetable.js ... var Vegetable = sequelize.define('Vegetable', { recipeId: { allowNull: false, ... }, name: { ... }, }); Vegetable.association = models => { Vegetable.belongsTo(models.Recipe); }; ... recipe.js ... var Recipe = sequeliz ...

The Google Maps application is experiencing an issue with rendering maps

Here is my code without the google map key. I am not receiving any errors, but the map is not showing up. What could I be missing? To test it out yourself, you will need to add your own map key which you can obtain from here. <!DOCTYPE html> <h ...

What is the best way to extend the functionality of npm script with command line arguments

After defining multiple scripts in my package.json file, I encountered an issue when attempting to run the $ npm run lint:fix command. The argument --fix did not get passed down to ./node_modules/.bin/standard, resulting in an error. { "name": "project" ...

sending a collection of elements to a jQuery function

I am puzzled by why this function is not working as expected when passing an array of items to it. My intention with the for-loop is to change the status of the child ctrl element to either '+' or '-'. An error occurred: Uncaught Typ ...

Enhancing the efficiency of a JavaScript smooth scrolling feature for numerous listed items

I have been experimenting with recreating the recent Apple Mac retrospective using only CSS and JavaScript to create a small timeline of projects. While I have successfully implemented the layout for the full-screen hero and the expand-on-hover effect, I a ...

Having trouble with JavaScript's Date.getUTCMilliSeconds() function?

I have a straightforward question for you. Take a look at this Angular App and try to create a new date, then print the number of UTC milliseconds of that date in the console. Can you figure out why it is returning zero? ...

Display the Image Element in Angular only when the image actually exists

In my HTML code, I have two sibling elements - one is an image and the other is a div. I want to display the image element if the image exists, and show the div element if the image doesn't exist. Here's how my elements are structured: <img ...

Developing an interactive selector within the on() event handler

My goal is to utilize the on() event for managing dynamically created code. It functions properly when the selector is hardcoded in the on() event. However, I aim to enable it to select different elements depending on which box they choose. $("body").on( ...

A step-by-step guide on utilizing vue3 with dayjs

Struggling to integrate dayjs with vue3 Before adding dayjs, everything was working fine. Now I'm encountering an error that says 'date_posted' is inaccessible and not displayed on the screen. Could there be a missing vue3 configuration? Is ...

Issue with mouseover in the jQuery area

As I navigate through a WordPress website, I am attempting to create a mandala using dynamic images. Utilizing jQuery and CSS areas, I aim to display the corresponding image when hovering over a specific section. However, I am facing an issue where there ...

Issue with VueJS not functioning properly upon initial interaction or initial trigger

After some trial and error, I was able to successfully create dynamic elements. The main goal of this exercise is to generate dynamic divs based on a specified "count", with the ability to add multiple textboxes inside each div. If you're curious to ...

Is commenting required? Well, meteor!

I am currently developing a chat application using Meteor and I am facing an issue where I want to require users to type something before sending a message (to prevent spamming by hitting enter multiple times). Unfortunately, I am unsure of how to achieve ...

Instructions on how to showcase a standard text within a designated text container

I am currently facing an issue with a textarea or textbox that is dynamically receiving URLs from a database. The textbox is displaying the full URL address, which is not visually appealing. I would like to replace this with some generic text such as "cl ...