VeeValidation always provides an accurate validation result

I recently integrated vee-validate into my project and encountered an issue with the validation behavior. Below is the code snippet from my component with a simple form group:

    <ValidationObserver ref="observer" v-slot="{ invalid }">
        <b-form @submit.prevent="onSubmit" novalidate>
            <b-form-group label="Amount">
                <ValidationProvider name="amount" rules="required|min_value:0" v-slot="{ errors }">
                    <b-form-input
                        :state="errors.length == 0"
                        v-model="form.amount"
                        type="text"
                        placeholder="Amount"
                    ></b-form-input>
                    <b-form-invalid-feedback :state="errors.length == 0">{{errors.join('. ')}}</b-form-invalid-feedback>
                </ValidationProvider>
            </b-form-group>
        </b-form>
    </ValidationObserver>

Despite importing ValidationObserver and ValidationProvider in the component, the validation does not work as expected.

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

The attached image shows the default behavior of the validation. It always appears green, regardless of the input or submission status.

The submit method is defined as follows:

       async onSubmit() {
            let validate = await this.$refs.observer.validate();
            console.log('VALID: ', validate)
        },

And it consistently returns true.

I am utilizing nuxt 2.9.x along with vee-validate 3.1.x for this implementation.

Answer №1

In order to use vee-validate effectively, it is necessary to extend it with custom rules using the extend method. You can refer to a detailed example provided in the documentation here:

import { extend } from 'vee-validate';
import { required, min_value } from 'vee-validate/dist/rules';

extend('min_value', min_value);
extend('required', required);

If you fail to extend vee-validate with your custom rules, they will be disregarded and the form will always be validated as valid.

For those working with nuxt, there are specific instructions available here.

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

Is there a way to dynamically set CSS variables within media queries using a JavaScript object?

Trying to pass a CSS variable into a media query for my Next.js project using theme-ui's sx property. I have styles set up like this: const styles = { headerLinkContainer: { width: '500px', justifyContent: 'space-ev ...

Is there a way to set the canvas size to match the exact window size in pixels without being affected by the browser's zoom factor?

I'm currently developing a website called sphere.mars2540.com. Is there a way in JavaScript or CSS to maintain a fixed canvas size regardless of the zoom level of the page, ensuring it always aligns with the actual pixels on the screen (even with 4k ...

The import error states that the object 'useHistory' is not available for export from the module 'react-router-dom'

Struggling with importing useHistory from 'react-router-dom' and encountering the error message: import error: 'useHistory' is not exported from 'react-router-dom'. Despite searching for solutions like Attempted import error: ...

How does the designated callback function in the filter method effectively remove any missing values from the array?

//Snippet of JavaScript code let sparseArray = [5, , 3, , 1]; let denseArray = sparseArray.filter(() => true); console.log(denseArray); The filter function in the callback removes empty elements from the sparse array. Output: [5, 3, 1] Explanation: ...

Is there a specific index range in javascript or nodejs for accessing array items?

I recently came across this Ruby code snippet: module Plutus TAX_RATES = { (0..18_200) => { base_tax_amount: 0, tax_rate: 0 }, (18_201..37_000) => { base_tax_amount: 0, tax_rate: 0.19 }, (37_001..80_0 ...

Tips for increasing the size of a textarea

I'm attempting to extend a textarea by adjusting the margin-top property, but it doesn't seem to be working as intended. Here is the code snippet in question: #sqlcontainerLoggedInPage2 { margin-top: 60px; } <div class="container-fluid" i ...

The gradual vanishing of principles

Below you will find text fields that I am populating with values that are later utilized in a JavaScript function. These fields are all contained within a form. The issue I am encountering is that when I submit the form, I initially get the correct value ...

What could be the reason for the token being undefined on the client side?

I have built an ecommerce site using nextjs and mongoose, integrating a jwt token in a cookie for client-side authentication. However, when trying to retrieve the token from the cookie named OursiteJWT, I encountered issues with it being undefined: https: ...

Is there a way to retrieve the height of a document using vh units in jQuery?

$(window).scroll(function() { $scrollingDiv.css("display", (($(window).scrollTop() / 100vh) > 0.1) ? "block" : ""); }); Is there a way to change the unit $(document).height()) > 0.1) to use 100vh instead? I'm still learning jQuery and would ...

Simultaneous fading and displaying of the navbar

Currently, I'm in the process of constructing a navigation bar using Bootstrap v4 and have encountered an issue with the collapsing animation in responsive view. Upon inspection of the specific navigation bar, I noticed that the classes (.in and .s ...

Enhance your AngularJS table with a custom Javascript context menu!

In the process of developing a shift planner, I have implemented a JS context menu and am attempting to display the shifts using Angular. However, upon clicking any table cell, all cells are being updated simultaneously. Is there a workaround for this issu ...

Transforming API Response into a structured format to showcase a well-organized list

When I make an API call for a list of properties, the data comes back unorganized. Here is how the data from the API looks when stored in vuex: posts:[ { id: 1; title: "Place", acf: { address: { state: "Arkansas", ...

Adjusting the camera's rotation focus in ThreeJS

I need help understanding how to change the rotation in THREEjs. I want my camera to rotate around my object instead of the standard point (0,0,0) because my Vector3 values are large (x, z, y). 4312872.381146194 66.59563132658498 -25727937.924670007 43124 ...

What is the process for generating an HTTP response that results in a pipe error being thrown

In my NestJS application, I have created a custom pipe that validates if a given value is a valid URL. If the URL is invalid, an error is thrown. This pipe is utilized in a controller to save an item into the database. Recently, I discovered that the pipe ...

Storing TypeScript functions as object properties within Angular 6

I am working on creating a simplified abstraction using Google charts. I have implemented a chartservice that will act as the abstraction layer, providing options and data-source while handling the rest (data retrieved from a REST API). Below is the exist ...

Variable declared in $scope suddenly losing its definition

Within my directive controller, I've implemented a $watch function as follows: $scope.$watch(function () { return service.abc; }, function(newVal, oldVal) { $scope.abc = {abc: newVal}; }); However, I've encountered issues with the variabl ...

Retrieve data using Ajax querying from a specific data source

Currently, I am attempting to construct a custom query using Ajax to interact with PHP/MySQL. Here is what I have so far: Javascript code: var i=2; fetchFromDBPHP("name", "tblperson", "id="+i); function fetchFromDBPHP(column, table, condition) { ...

Craving assistance in coding permutations

Thank you for responding. I want to express my gratitude for your efforts in trying to assist me. Unfortunately, I have posted this problem on multiple websites and no one has been willing to help. Regarding my code, my objective is to count permutations. ...

The term 'string' is typically employed as a data type, yet in this instance it is being utilized as an actual value

Just started working with TypeScript and encountered an issue while trying to set the state. Encountered this error message: 'string' is a type and cannot be used as a value here. const state = reactive({ user: { uid: "", ...

What steps can be taken to encourage a client to download a file from a webpage that is password-protected?

I've encountered a challenge with my FTP server, as it is password protected and I want users to be able to download from it via a button on my website without revealing the password. Currently, I am using puppeteer to bypass the authentication proces ...