department-of-veterans-affairs / vets-design-system-documentation

Repository for design.va.gov website
https://design.va.gov
40 stars 61 forks source link

Add more robust validation, similar to `FileField`, for `VaFileInputMultiple` #3349

Open JoshingYou1 opened 2 weeks ago

JoshingYou1 commented 2 weeks ago

Bug Report

What happened

What I expected to happen

Reproducing

Steps to reproduce:

  1. Create a VaFileInputMultiple component.
  2. Add the following code to the component's attributes: accept=".pdf, .doc, .docx, .jpg, .jpeg, .rtf, .png"
  3. Change the file extension of a .gif file to .doc and upload it. It should let allow you to upload it with no validation errors, which is not the desired outcome.

Urgency

How urgent is this request? Please select the appropriate option below and/or provide details

Details

FileField Behavior Image VaFileInputMultiple Behavior Image

caw310 commented 2 weeks ago

Hey team! Please add your planning poker estimate with Zenhub @Andrew565 @ataker @harshil1793 @it-harrison @jamigibbs @micahchiang @powellkerry @rsmithadhoc

jamigibbs commented 2 weeks ago

Hi @JoshingYou1. What is the FileField component? This is not something that is currently in the VA design system. Can you link to it?

JoshingYou1 commented 2 weeks ago

Hi @JoshingYou1. What is the FileField component? This is not something that is currently in the VA design system. Can you link to it?

Maybe component is the wrong word? Here's the link: https://github.com/department-of-veterans-affairs/vets-website/blob/main/src/platform/forms-system/src/js/fields/FileField.jsx

micahchiang commented 2 weeks ago

@JoshingYou1 - Teams do have the ability to pass custom validation functions to VaFileInputMultiple through the use of the onVaMultipleChange prop. Here are the docs which show an example of this.

JoshingYou1 commented 2 weeks ago

@JoshingYou1 - Teams do have the ability to pass custom validation functions to VaFileInputMultiple through the use of the onVaMultipleChange prop. Here are the docs which show an example of this.

Yes, I've read through the docs. Is there a straight-forward way to integrate what is in FileField into the onVaMultipleChange prop though?

micahchiang commented 2 weeks ago

The prop accepts a callback and exposes an event that contains file information. What you could probably do is either use these file validators directly in whatever call back you pass in, or adapt them to your specific needs and then pass them in.

FileField is pretty tightly coupled to react-json-schema, so integrating what's in that file directly probably won't work. The validators I linked to are more agnostic.

If you're looking to use multiple file input in a form that uses react-json-schema, the forms team does provide a va file input field with the necessary bindings, though I'm not sure if adapting va file input multiple is on their roadmap.