Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

ejfine
Copy link

@ejfine ejfine commented Oct 21, 2025

Added section on error pattern for form controls, detailing how to display validation errors for nested state values using a regular expression.

πŸ”— Linked issue

Resolves #4573

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)

πŸ“š Description

Adds clarification of how to use the errorPattern prop to allow more complex form elements to render validation failure messages.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

Added section on error pattern for form controls, detailing how to display validation errors for nested state values using a regular expression.
Comment on lines 150 to 165
::component-code
---
prettier: true
ignore:
- label
props:
label: List of IDs
error-pattern: /ids.*/
slots:
default: |

<UInputTags v-model="state.ids" class="w-full" />
---

:u-input-tags{v-model="state.ids" class="w-full"}
::
Copy link
Member

@benjamincanac benjamincanac Oct 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ComponentCode component automatically renders the component and the code based on the provided prop, the trick here is to add a slug since we're not in the input-tags component.

Suggested change
::component-code
---
prettier: true
ignore:
- label
props:
label: List of IDs
error-pattern: /ids.*/
slots:
default: |
<UInputTags v-model="state.ids" class="w-full" />
---
:u-input-tags{v-model="state.ids" class="w-full"}
::
::component-code{slug="input-tags"}
---
prettier: true
ignore:
- label
- class
props:
label: List of IDs
errorPattern: /ids.*/
class: 'w-full'
---
::

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I pulled that suggestion in. none of the other component-code sections on that page have slugs though...but maybe UInput is just always available?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No sorry, my suggestion was wrong πŸ˜… We do want to render a FormField first.

Now I'm thinking about it, it might be better to use a :component-example here with an actual FormFieldErrorPatternExample.vue component that uses a Form to show the validation.

@benjamincanac benjamincanac changed the title docs: UFormField errorPattern prop details docs(form-field): add error-pattern section Oct 21, 2025
@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 21, 2025

npm i https://pkg.pr.new/@nuxt/ui@5284

commit: 6bc3313

Comment on lines 150 to 159
::component-code{slug="input-tags"}
---
prettier: true
ignore:
- label
- class
props:
label: List of IDs
errorPattern: /^ids\..*/
class: 'w-full'
Copy link
Contributor

@vercel vercel bot Oct 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
::component-code{slug="input-tags"}
---
prettier: true
ignore:
- label
- class
props:
label: List of IDs
errorPattern: /^ids\..*/
class: 'w-full'
::component-code{slug="input-tags-form-field-example"}
---
prettier: true

The documentation example uses slug="input-tags" but specifies FormField props (label, errorPattern), which don't belong to the InputTags component. This mismatch will likely cause the example to not render correctly.

View Details

Analysis

FormField documentation uses wrong component slug causing props mismatch

What fails: Line 150 in docs/content/docs/2.components/form-field.md uses ::component-code{slug="input-tags"} with FormField props (label, errorPattern) that don't exist on UInputTags component

How to reproduce:

  1. Open docs/content/docs/2.components/form-field.md line 150
  2. The ::component-code{slug="input-tags"} tries to render UInputTags component
  3. Props label: "List of IDs" and errorPattern: /^ids\..*\/ are passed but UInputTags only accepts props like modelValue, placeholder, disabled, etc.

Result: Component code example shows InputTags without FormField wrapper, ignoring the label and errorPattern props that are central to this documentation section

Expected: Should show InputTags properly wrapped in FormField to demonstrate the errorPattern feature, using existing input-tags-form-field-example component

Fix: Changed slug from input-tags to input-tags-form-field-example to reference the correct example component that demonstrates InputTags within FormField context

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benjamincanac - is this more correct than your suggestion about the slug? I'm not sure exactly how these slugs and component-code things work

@ejfine
Copy link
Author

ejfine commented Oct 21, 2025

oh wow, that's super neat! you can see how the docs rendered here: https://ui-5tsvjco9r-nuxt-js.vercel.app/docs/components/form-field#error-pattern

Added 'name' prop and 'errorPattern' to UInputTags example.
@ejfine
Copy link
Author

ejfine commented Oct 21, 2025

ok, @benjamincanac - it looks like this now:

image

This sets the `color` to `error` on the form control. You can change it globally in your `app.config.ts`.
::

### Error Pattern
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example should be on the Form component since it's not functional without a Form.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@romhml @benjamincanac - do you think the entire thing should be moved to the Form page? or that there should be an example within the form-field.md page that shows it being used within a Form?

#5284 (comment)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be better in the Form page yes, we need a Form to demonstrate this anyway.


### Error Pattern

Nested state values will not show up by default as validation-failed messages below the form control. This is particularly relevant for components such as UInputTags and USelect. Providing a regular expression via this prop will allow those form errors to be detected and displayed. The regular expression will be matched against the `name` key's value within the `errors` list of the `FormErrorEvent`.
Copy link
Member

@romhml romhml Oct 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rephrase it to make it more concise

Suggested change
Nested state values will not show up by default as validation-failed messages below the form control. This is particularly relevant for components such as UInputTags and USelect. Providing a regular expression via this prop will allow those form errors to be detected and displayed. The regular expression will be matched against the `name` key's value within the `errors` list of the `FormErrorEvent`.
Use the `error-pattern` prop on the [FormField](/docs/components/form-field) component to match nested form errors. This is especially relevant for components with array values such as [InputTags](/docs/components/input-tags).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v4 #4488

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UInputTag does not display validation errors for pattern matching

3 participants