Errors are not displayed in vee-validate for objects

When utilizing

the problem arises while attempting to validate a nested object and displaying an error.

An example was created based on the documentation.

However, when trying to include

:has-error="Boolean(formErrors.links?.twitter)"

an error occurs when showing the popup message.

The error states: Property 'twitter' does not exist on type 'string'

Here is the component script:

<script setup lang="ts">
// imports...libs
// const { value: name } = useField('name')
// const { value: twitter } = useField('links.twitter');
// const { value: github } = useField('links.github');

const { values: fieldValues, errors: formErrors, handleSubmit } = useForm({
  initialValues: {
    name: '',
    links: {
      twitter: null,
      github: null,
    },
  },
  validationSchema: yup.object({
    name: yup.string().required(),
    links: yup.object({
      twitter: yup.string().required().nullable(),
      github: yup.string().required().nullable(),
    })
  })
})
const onSubmit = handleSubmit(values => {
  //some logic
});

const loading = ref(false)

</script>

And the component HTML:

<template>
  <form @submit="onSubmit">
    <Field v-slot="{ field, errors }" name="name" type="text">
      <VField label="name">
        <VControl icon="feather:edit-2" :has-error="Boolean(formErrors.name)">
          <input
            v-bind="field"
            class="input is-primary-focus"
            type="text"
            placeholder="imagesLtr"
            autocomplete="name"
          />
          <p v-if="errors" class="help is-danger">{{ formErrors.name }}</p>
        </VControl>
      </VField>
    </Field>
    <Field v-slot="{ field, errors }" name="links.twitter" type="text">
      {{ field }}
      <VField label="links.twitter">
        <VControl icon="feather:edit-2" :has-error="Boolean(formErrors.links?.twitter)">
          <input
            v-bind="field"
            class="input is-primary-focus"
            type="text"
            placeholder="Name"
            autocomplete="twitter"
          />
          <p v-if="errors" class="help is-danger">{{ formErrors.links?.twitter }}</p>
        </VControl>
      </VField>
    </Field>
    <button>Submit</button>
  </form>
</template>

Answer №1

Give formErrors['links.twitter'] a shot?
This method allows you to handle errors within nested objects while utilizing vee-validate with the composition api
Might be beneficial

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

How to access saved values in WebdriverIo using Typescript

I am currently using WebdriverIO along with Typescript for automating an Android app. Scenario: Go to the Training Page Get the Session name (This value changes dynamically) I want to store the retrieved session name in a variable and then later assert ...

What is the best way to update datatables in Laravel vuejs with fresh data?

Currently, I am utilizing datatables 1.10.19 within vue js and encountering an issue with refreshing the table post inserting new data into the database. Despite trying methods like clear, destroy, and draw, none seem to be effective in achieving the des ...

I'm looking to configure @types for a third-party React JavaScript module in order to use it with TypeScript and bundle it with webpack. How can I accomplish this?

Imagine you have a third-party npm package called @foo that is all Javascript and has a module named bar. Within your TypeScript .tsx file, you want to use the React component @foo/bar/X. However, when you attempt to import X from '@foo/bar/X', y ...

Fetch HTML content from a local file using Vue

I am currently searching for a method to import HTML content from a file located at /src/activities/0/2/content.html The specific numbers in the path are interchangeable variables. My goal is to achieve something along the lines of mounted(){ this ...

How can I utilize npm with the original source code instead of minified or bundled code?

I am looking to access npm and JavaScript (or TypeScript) 3rd party libraries directly from the source code. Similar to how I can make changes in Python libraries by going into their source code, I want to have the same capability with my JavaScript depen ...

Subtracting Arrays Containing Duplicates

Imagine having two arrays defined like this: const A = ['Mo', 'Tu', 'We', 'Thu', 'Fr'] const B = ['Mo', 'Mo', 'Mo', 'Tu', 'Thu', 'Fr', 'Sa&ap ...

Issue: Formcontrolname attribute is undefined causing TypeError when trying to retrieve 'get' property.Remember to define formcontrolname attribute to

Having trouble creating a form at the moment and keep encountering this error: 'ERROR TypeError: Cannot read property 'get' of undefined' Even after trying various solutions like using formControlName in brackets or accessing the va ...

What is the best way to access a state variable that has a union data type?

Is there a way to access a field of a state variable with a union type in TypeScript? Here is an example of a zustand store I have defined: import { create } from 'zustand' type HeightUnit = 'cm' | 'ft\' in"&ap ...

In Vue, when you want to display text after reaching a height of 50px, any additional text will automatically be replaced by five full

https://i.stack.imgur.com/mp0YJ.png >>>>>>>>>Explore Sandbox Example <div style="height:50px"> ...

Using Typescript to create a Checkbox Grid that displays pipe-delimited values and implements a custom validation rule

I am currently working with a checkbox grid that contains pairs of AccountIds (consisting of x number of digits) and file names separated by a pipe delimiter. The file names are structured to always begin with either PRC or FE followed by a varying combin ...

Unable to utilize material tabs in this situation

Discovering the material tabs feature at https://material.angular.io/components/tabs/api#MatTab got me excited to implement it in my project. After adding the suggested import, I encountered an issue where I couldn't find the module "@angular/materia ...

Having trouble locating the data-testid attribute within a Vue Component using Jest

I need assistance in constructing a test that specifically selects an element utilizing the data-testid attribute. The scenario involves a BaseTile component structured as follows: <template> <div data-testid="base-tile-icon&quo ...

Designing a customized element by deriving from an existing Vue component

I am working on a Vue 2 with Bootstrap project and have multiple buttons that look like this: <b-button variant="outline-secondary" title="..." v.b.tooltip.hover.bottom> <font-awesome-icon icon="..." /> </b- ...

Do we really need Renderer2 in Angular?

Angular utilizes the Renderer2 class to manipulate our view, acting as a protective shield between Angular and the DOM, making it possible for us to modify elements without directly interacting with the DOM ourselves. ElementRef provides another way to al ...

Fix a typing issue with TypeScript on a coding assistant

I'm struggling with typing a helper function. I need to replace null values in an object with empty strings while preserving the key-value relationships in typescript // from { name: string | undefined url: string | null | undefined icon: ...

Sort and incorporate elements by multiple strings present in an array

Looking to filter and include strings in an array by matching them with items in another array? Here is a sample code snippet that filters based on a single string: const filteredString = `${this.filter}`.toLowerCase(); this.filteredCampaigns = this. ...

"What could be causing my React Native app to build without any issues even though the TypeScript compiler is throwing

Recently, I decided to explore TypeScript in combination with Expo. I took the time to set up linter and formatter integrations like typescript-eslint to help me catch errors while coding. Periodically, I run npx tsc to ensure my code compiles correctly an ...

React Formik - application triggers an undesired submission request when the Enter key is pressed in the input field

Whenever I enter a value in the "name" field and hit Enter, the app sends a request and the address bar in the web browser changes to http://localhost:3000/?name=something. However, if I simply add another input field to the form, the app's behavior c ...

A method to access a stored value in localStorage that does not involve utilizing the __zone_symbol__value property

I am encountering a problem with localStorage. After storing user information in localStorage, I am unable to retrieve it without using the __zone_symbol__value property of the parsed value. This is how I store data into locaStorage localStorage.setItem(& ...

Is there a native feature in Vue.js that allows for the addition of a duplicate of a constantly saved object to an array that is repeated

Having an issue with my Vue.js app where adding a newItem to a list of items results in the added object being bound to the input. Here's what I've tried so far: new Vue({ el: '#demo', data: { items: [ { start: & ...