The inability to show validation errors within the form to the user

this is my unique form code

 <form @submit.prevent="updatePassword">

                        <div class="form-group">
                            <label>Old Password</label>
                            <input v-model="form.old_password" type="password" name="old_password"
                                   class="form-control" :class="{ 'is-invalid': 
form.errors.has('old_password') }">
                            <has-error :form="form" field="old_password"></has-error>
                        </div>

                        <div class="form-group">
                            <label>New Password</label>
                            <input v-model="form.password" type="password" name="password"
                                   class="form-control" :class="{ 'is-invalid': 
form.errors.has('password') }">
                            <has-error :form="form" field="password"></has-error>
                        </div>

                        <div class="form-group">
                            <label>Confirm New Password</label>
                            <input v-model="form.password_confirmation" type="password" 
name="password_confirmation"
                                   class="form-control" :class="{ 'is-invalid': 
form.errors.has('password_confirmation') }">
                            <has-error :form="form" field="password_confirmation"></has-error>
                        </div>

   <button :disabled="form.busy" type="submit" class="btn btn-primary">Update Password</button>
                    </form>

this is the script I used for password update

<script>

export default {
    name: "Password",
    data(){
        return{
            form: new Form({
                old_password: '',
                password: '',
                password_confirmation: ''
            }),
        }
    },
    methods:{
        updatePassword(){
            axios
                .post(`/data/password/update/${this.$parent.userId}`, this.form)
                .then((response) => {
                    if(response.data === 'success'){
                        Swal.fire(
                            'Update',
                            'Password Updated Successfully',
                            'success'
                        );
                    }
                })
                })
        },
    },
    mounted() {

    }
}
</script>

this is how I import and use VForm in my Vue application

import {
Form,
HasError,
AlertError,
AlertErrors,
AlertSuccess
} from 'vform';

window.Form = Form;
Vue.component(HasError.name, HasError);
Vue.component(AlertError.name, AlertError);
Vue.component(AlertErrors.name, AlertErrors);
Vue.component(AlertSuccess.name, AlertSuccess);

here is how I validate the request in Laravel backend

public function passwordUpdate(Request $request, $id)
{
    $this->validate($request, [
        'old_password' => 'required',
        'password' => 'required|string|min:8|confirmed',
    ]);
}

after submitting an empty form, I am encountering a rendering error

Error in render: "TypeError: _vm.form.errors.has is not a function"

I need assistance with resolving this issue. What could be the potential cause of the error?

Answer №1

Within the method updatePassword, you utilized axios directly. However, in cases where you wish for vform to handle it on your behalf, make use of form.post in this manner:

    methods:{
        updatePassword(){
             this.form.post(`/data/password/update/${this.$parent.userId}`)
                .then((response) => {
                    if(response.data === 'success'){
                        Swal.fire(
                            'Update',
                            'Password Updated Successfully',
                            'success'
                        );
                    }
                })
            })
        },
    },

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

Steps to deploy a project built with Vue.js and Flask on an Apache server

I successfully built a project using Vue.js for the front end and Flask for the backend. Following an example found here, I structured my files with the Vue.js build files located in a "dist" folder within the same directory as the main Python script, run ...

url-resettable form

Currently, I am working on an HTML form that includes selectable values. My goal is to have the page load a specific URL when a value is selected while also resetting the form back to its default state (highlighting the "selected" code). Individually, I c ...

Utilizing jQuery to target a select element's two specific children

I am trying to target the parent element by matching two specific children elements. Here is my code: $('span:contains("11:00am"), span.name:contains("Tom")').parents("a").css("background-color","rgb(255, 255, 255)"); <script src="https://c ...

Instructions on integrating a column of buttons into a Bootstrap table containing information retrieved from a MySQL database

My bootstrap table is currently displaying data that is loaded from a MySQL database. I am looking to enhance it by adding a column with buttons, similar to the layout shown in this image. https://i.stack.imgur.com/8fWfR.png However, I am facing some dif ...

Obtain the name of the model in Vue.js using either the input's ID or name attribute

Is it possible to retrieve the model name using the input ID? <input v-model="data.name" id="name_db"> I have a value for data.name in the database. Prior to using Vue.js, I accomplished this task with the following code: values ...

Generate a graphical representation with react-d3

In an attempt to create a histogram using react-d3-components, I have the following code: import React, { Component } from 'react'; import * as d3 from 'd3'; import * as ReactD3 from 'react-d3-components'; import propTypes fr ...

What are the advantages of choosing express.js over Ruby on Sinatra?

Currently brainstorming for a social app and contemplating the switch from my initial option, Sinatra/Ruby to express.js/nodejs. My main focus is on the abundance of open source projects in Ruby that can expedite development. Another major consideration i ...

What is the process of declaring state in React components?

I have recently started learning React and I am curious about how this code snippet should function: class App extends Component { > 4 | state = { | ^ 5 | bands: [], 6 | concerts: [] 7 | } Below is the error message being ...

Storing information in the DOM: Choosing between Element value and data attribute

When it comes to storing values in a DOM element, we have options like using the data attribute. For example, $("#abc").data("item", 1) can be used to store values and then retrieve them with $("#abc").data("item"). However, I recently discovered that th ...

Difficulty encountered when creating step definitions - Implementing Cucumber and Appium using JavaScript

I am currently embarking on a project that serves as more of a proof of concept. For me, this is a POC since I am aware that similar projects have been executed before. My focus revolves around working with Cucumber.js, Appium Server/Client, Node, and Jav ...

A comprehensive guide on parsing a file containing multiple JSON objects in PHP using Laravel

Looking at my input file, I see something along these lines: {"name": "foo"}{"name": "bar"} Is there a way to properly parse this data? ...

Inserting a new key-value pair into each object within an array

I have a collection of items that I need to add a specific key to in AngularJS using $scope. The following code shows the initial objects: $scope.Items = [ {name:'Jani',country:'Norway'}, {name:'Hege',country:'Sw ...

Issue with incremental static generation in version 13 not functioning as expected

Is ISR working for anyone in the NextJS 13 Beta version? I have set revalidate to 15 as follows. export const revalidate = 15; However, even after running `npm run build`, the page still remains a statically generated site (SSG). The symbol is showing u ...

Determine the overall cost based on varying percentage increases for each step

I am currently working on developing a price estimation calculator. Here is the breakdown: For 1000 MTU, the price will be 0.035, resulting in a total of 35. For 2000 MTU, the price will be 0.034, making the total 67. For 3000 MTU, the price will be 0.03 ...

Multiple 'keydown' events are accumulating with Ajax activated

When the search field is focused, I am loading JSON into the browser and then iterating over the JSON objects to find real-time results 'on keydown'. The issue I'm encountering is detailed in the console after the initial block of code Aja ...

effective ways to extract objects from nested structures using a specific identifier

In this sample data, I am looking to filter an object based on its ID key let myData = { "nodeInfo": { "9": { "1": { "ID": "14835" ...

Storing Data with expressjs/session in NodeJS

My development project involves 3 files: app.js, index.js (routes), and Users.js (controller). Upon successful user login (verification between POST data and the database), I aim to store information in a session using expressjs/session. Below is how I c ...

Show the current time of a track using VueJS

Is there a way to have the time continuously update itself without needing to click on anything? When I press play, I want the seconds to automatically start updating from 0:00 until the end of the audio track. Currently, the time only updates when clicked ...

Utilize a dual-color gradient effect on separate words within the <li> element

I am attempting to display the fizz buzz function in an unordered list, with each word being a different color ('fizz'-- green, 'buzz'--blue) as shown here: https://i.sstatic.net/Yvdal.jpg I have successfully displayed "fizz" and "buz ...

When an event is triggered in Angular Component, the object is not properly defined in the handler causing errors

While experimenting with createjs and angular, I encountered an issue when trying to update my stage after an image loads. It seems like there might be a problem related to Angular in this situation. Upon completion of the load event on the Bitmap object a ...