Utilizing Vuelidator in VueJs to validate input values and handle error messages

Upon reviewing the documentation for Vuelidator at this particular link, I encountered an error when attempting to utilize this specific javascript package:

[Vue warn]: Error in v-on handler: "TypeError: target is undefined"

The process of installing the package within my project, specifically in app.js, involved the following steps:

import Vue from "vue";

const {default: Vuelidate} = require('vuelidate')
Vue.use(Vuelidate)
require('./bootstrap');


window.Vue = require('vue').default;

new Vue({
    components:
        {
            //...
        }
}).$mount('#app');

Furthermore, the content of the user-profile component is as follows:

import {mapGetters, mapMutations} from "vuex";

import { required, minLength, between } from 'vuelidate/lib/validators'

export default {
    props: [
        'user'
    ],
    data() {
        const userInfo = this.user;
        return {
            name: userInfo.name,
        }
    },
    validations: {
        name: {
            required,
            minLength: minLength(4)
        }
    },
    computed: {
        //...
    },
    methods: {
        change_name({target}) {
            this.$store.commit('change_name', target)
            this.$v.name.$touch()
        }
    }
};

Additionally, the corresponding HTML input tag is included below:

<input v-model.trim="name" type="text" name="name" dir="auto"
       @input="change_name($event.target.value)"
       class="form-control">

Why am I receiving a

"TypeError: target is undefined"
error and what steps can be taken to address this issue? Thank you in advance for your assistance.

Answer №1

When working with the `change_name` method, make sure to remove the curly brackets when using destructuring assignment on strings. Update change_name({target}) to simply change_name(target).

It might also be beneficial to rename the `target` argument to something more suitable such as `newName`.

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

Prevent FullCalender date cells from resizing when additional events are added

I am currently utilizing JQuery's FullCalendar plugin for my project and I have observed that the date cells expand when multiple events coincide on a single date. For example, as shown in this image, the date cell for February 4 is expanding. Is the ...

Expanding Text Box

My goal is to create a textarea that automatically adjusts its size as the user types or pastes long text into it. This is my current implementation. class AutoResizeTextArea extends InputBase { render() { const { label, placeholder, wrap, ro ...

javascript - developing a neutral constructor

Similar Question: Constructors in Javascript objects I am exploring the concept of creating classes in JavaScript. I am struggling to grasp it fully. Now, I am curious if it's possible to create a constructor in JavaScript, similar to what can b ...

The issue arises when React child props fail to update after a change in the parent state

Here's the main issue I'm encountering: I am opening a websocket and need to read a sessionId from the first incoming message in order to use it for subsequent messages. This should only happen once. I have a child component called "processMess ...

Accessing the react-bootstrap tab using the history feature in React

Currently, I am in the process of developing a multi-form page that includes login, registration, and lost password functionalities displayed using tabs with react-bootstrap. The technologies I am using for this project are react 17.0.2, react-bootstrap 2 ...

Configuring environment variables during Jest execution

A variable is defined in my `main.ts` file like this: const mockMode = process.env.MOCK_MODE; When I create a test and set the variable to true, it doesn't reflect as `'true'` in the main file, but as `'false'` instead. describe ...

A Sparkling occurrence that is activated upon the completion of plot rendering

I am looking for a way to detect when the plots in a Shiny dashboard tab have finished rendering so that I can hide a loading page element. Currently, I am using the following code: observeEvent("plot", hide(id = "loading-content", anim = TRUE, animType = ...

Injecting a full browser-screen DIV into the body of the webpage

Recently, I was tasked with developing a script that could be utilized on any website. As a test, I decided to use the Google search results page. My goal is simple - to have a full-screen semi-transparent div displayed on any site for cookie notification ...

What is the process for storing a particular model in a designated collection within MongoDB's database?

I am working with three different models: user, teacher, student. All of these are stored in the database under the users collection. However, I want to save the student model in its own separate collection called students, instead of mixing it with the us ...

Is the callback of $.post not being executed until the loop it's contained in finishes?

I'm working on a stock table that allows users to input the quantity of stock to issue. I have a function that verifies whether or not the database has sufficient stock for each entry in the table. When debugging through the code in Chrome, I noticed ...

Adjusting the dimensions of the central container

Does anyone have suggestions on how to resize the middle red container when the window is resized, considering the fixed-width black containers on the left and right? I am aware that this can be achieved using jQuery by calculating the window width and a ...

Having trouble with the speed of multiple jQuery posts?

We have encountered some challenges with calling multiple jQuery posts since switching to our new server. On certain pages, we are making multiple jQuery post requests as shown below: $.ajax({ type: "POST", url: "../files/processed/includes/proce ...

The iFrame that is generated dynamically becomes null when accessed from a page that has been loaded using JQuery

One issue I am facing is with a dynamically created iframe in regular javascript. It functions perfectly fine when called from a static page using conventional methods. However, when it is being called from a page loaded by jQuery, I encounter an error s ...

I am having issues with the drag and drop directives in AngularJS - they work fine on my computer's navigator, but they

I have successfully implemented drag and drop directives in angularJS, and they are functioning properly on my computer's web browser. However, when I tried to use the directives on my touch devices, they did not work. Should I make adjustments to my ...

What could be causing this code to malfunction on a mobile device?

I am struggling to make this drag and drop function work on mobile devices. Despite implementing the code, it doesn't seem to function properly when accessed on my mobile phones. Here is the snippet of the code: copy = 1; $('.dragArea img&apo ...

Refreshing the page when the hide/show button is clicked with jQuery

I have a situation where I am using jQuery to toggle the visibility of a div by clicking on show/hide buttons. However, I am facing an issue where the code does not work as intended. Every time I click the buttons, the div reverts back to its original stat ...

Guide to integrating the Braintree API with Node.js

I am trying to implement Braintree for website payment gateway, but I encountered an issue while following the online guidelines. The code seems to be incompatible with Node.js. Am I missing something? Index.js: //send token to clients app.get("/client_t ...

When the button is clicked, the ng-click event will trigger the addClass function, but only on the second click

My bootstrap alert has this structure: <div id="errorAlert" class="alert col-md-6 col-md-offset-3 fadeAlert" ng-if="itemExistsAlert"> <button type="button" class="close" data-dismiss="alert">&times;</button> <p>{{alertM ...

Extracting a nested property from a JSON object without relying on the lodash get method

We have a sample json data: { "name": "app", "version": "0.1.0", "description": "Sample description", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "repository": { "type": "git", "url": "so ...

Browsing a Collection of Objects within an Array in JavaScript

After making an ajax request to load a JSON file and parsing it to store a reference to the object, I encountered issues while trying to loop through the object due to its structure. Below is a snippet of the JSON data that I am working with: { "marker ...