Skip to content

Nested form validation array of messages #2389

@719media

Description

@719media

For what version of Nuxt UI are you suggesting this?

v2.x

Description

It would be cool if the errors array from UForm supported the message parameter having an array value (multiple messages). The default backwards compatible method could just join them with a space or something. (See https://ui.nuxt.com/components/form-group#props)
That is all.

Additional context

No response

Activity

self-assigned this
on Nov 1, 2024
github-actions

github-actions commented on Feb 15, 2025

@github-actions

This issue is stale because it has been open for 30 days with no activity.

Dominic-Marcelino

Dominic-Marcelino commented on Mar 31, 2025

@Dominic-Marcelino

In case anyone else comes across this: In v3 the Form component provides the full error array. This way you can access it in any child:

const formErrors = inject<Ref<FormError[]> | null>('form-errors', null);
added a commit that references this issue on Jun 14, 2025
5829aeb
romhml

romhml commented on Jun 29, 2025

@romhml
Member

We decided not to move forward with this to avoid introducing confusion by adding a errors alongside the existing error property.

You can however implement a simple component around the FormField to achieve this:

<script setup lang="ts">
import type { FormFieldProps, FormError } from '@nuxt/ui'

const props = defineProps<Omit<FormFieldProps, 'error'> & {
  errors?: string[]
}>()

const formErrors = inject<Ref<FormError[]> | null>('form-errors', null)

const errorMessages = computed(() => {
  return props.errors ?? formErrors?.value?.map(e => e.message)
})
</script>

<template>
  <UFormField v-bind="props">
    <slot />
    <template v-if="errorMessages" #error>
      <p v-for="error in errorMessages">
        {{ error }}
      </p>
    </template>
  </UFormField>
</template>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @benjamincanac@719media@romhml@Dominic-Marcelino

    Issue actions

      Nested form validation array of messages · Issue #2389 · nuxt/ui