Custom validation to avoid equal names in multiple files input

Hey everyone, I'm trying to write a custom validation rule to block files with equal names being uploaded in multiple files input. Couldn't find any other question regarding this. Is it possible? Thanks!

Hi @Vitor_Dal_Pra
Welcome to the community.
Running your query which contains the file names, and then using ternary operator in the custom validation rules might do the trick. Here is the example, you will just need to adjust it to your components

Hey @Vitor_Dal_Pra, it is definitely possible!

I assume you want to ensure your users do not accidentally upload the same files. In this case, the validation rule would look like this:

{{ fileDropzone1.value.map(obj => obj.name).length !== new Set(fileDropzone1.value.map(obj => obj.name)).size ? 'Some files have the same name.' : null }}

Still if you would like to validate against the file names that already exist on the server, then @Milan_Kalem 's solution is good to go.

Hope this helps

Hey, @Milan_Kalem and @preshetin thank you for your answers!

I actually need to combine both your answers. I need to check if the name of a file in the input form is not already in the database and if this file does not match the name of other files while "in" the input.

Then you can use something like this

{{
  fileDropzone1.value.map(obj => obj.name).length !== new Set(fileDropzone1.value.map(obj => obj.name)).size 
  ? 'Some files have the same name.' 
  : fileDropzone1.value.some(obj => obj.name.split('.')[0] === query5.data.name[0]) ? "Database duplicate" : "Free to upload"
}}

:sunny:

Hey @Milan_Kalem, thank you!

The code is not working for the database part. I believe it has to do with query29 returing a json, but could not figure it out on how to solve it...


This is where im stuck right now

Another two cents from me.

Why do you want to ensure the all filenames are unique?

If during saving files to your file storage you would add some random hash then the problem would go away by itself