Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileInput does not show validation in helper text as IsTouched property is always false #9446

Closed
wattry opened this issue Nov 15, 2023 · 1 comment
Assignees

Comments

@wattry
Copy link

wattry commented Nov 15, 2023

What you were expecting:
When using a file input in RA v4.15.0 the FileInput component should show validation errors in the helper text component when validation errors occur.

What happened instead:
The isTouched fieldState property does not change even when the input has values added or removed (Tested by creating the component locally). However, the isDirty fieldState value does change. This results in the validation error not being displayed on the input.

Steps to reproduce:
Use the following code in any react admin create resource

const CreateResource = () => {
  const filesSizeValidation = (files) => {
    if (files) {
      // The sum of the file sizes cannot exceed 10MB
      const totalSize = files?.reduce((total, file) => (total += file?.rawFile?.size || 0), 0);

      if (totalSize > limit) {
        return 'Total upload size exceeds 9MB limit';
      }
    }

    return undefined;
  };

  return (<Create>
    <SimpleForm>
      <FileInput
        source="files"
        multiple={true}
        validate={filesSizeValidation}
        helperText="A maximum of 3 files not exceeding 10MB in total"
      >
        <FileField source="title" />
      </FileInput>
    </SimpleForm>
  </Create >);
};

Environment

  • React-admin version: v4.15.0
  • Last version that did not exhibit the issue (if applicable):
  • React version: 17.0.2
  • Browser: Chromium & FireFox
@erwanMarmelab erwanMarmelab self-assigned this Nov 15, 2023
@erwanMarmelab
Copy link
Contributor

Hi @wattry ,

The natural way of working our input is not to show errors before the first validation. If you want to change from onSubmit error check to onBlur, please check this documentation.
If it doesn't answer your question or you are not okay with it, please make a codesandbox.

Cheers,

Erwan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants