Skip to content

[field] Option or way to run the validation function after checkValidity #1904

Closed
@benjavicente

Description

@benjavicente

Feature request

Summary

In a Field, I want to run a validation only after the native input validation has run, such that a customErroris only shown if there aren't any non-custom errors.

Here is a codepen: https://codesandbox.io/p/sandbox/clever-chihiro-ssw6fd?file=%2Fsrc%2FApp.tsx

See that Field.Error with customError is rendered when the pattern is also invalid.

On those cases, the preferred way would be to use a validation library like zod, or there is an intended way to run a validation function after the validity of the input was checked?

A way to hack around this limitation would be to get a ref of the input element and run checkValidity inside the validation function. Uncomment the first line of the validation function to see that.

Examples in other libraries

Couldn't find a similar example.

Motivation

My use case is to run a chek digit function after the field is completed (passing required validation) and if it matches a regular expression (patter validation). I want to avoid repeating code, ej validating the pattern on the validation function and on the element itself.

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions