Skip to content

Don't validate on blur if field is not dirty #1289

@david-crespo

Description

@david-crespo

This validation is a little aggro.

2022-11-07-aggro-validation

You shouldn't get screamed at if all you do is blur the field (e.g., to look at the rest of the form if the form is longer). My first thought is that we can simply not validate on blur until the field (or the form?) is empty. I kind of doubt we can implement this on the form itself using mode because the options are pretty flat — submit, blur, change, touched, all. However, it would be pretty do at the display layer: regardless of whether there is an error on the field, only show it under certain conditions, which we can pull from the field and form state.

render={({ field, fieldState: { error } }) => {
return (
<>
<UITextField
title={label}
type={type}
error={!!error}
aria-labelledby={cn(`${id}-label`, {
[`${id}-help-text`]: !!description,
})}
aria-describedby={description ? `${id}-label-tip` : undefined}
{...field}
{...props}
/>
<ErrorMessage error={error} label={label} />
</>
)
}}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions