Confiforms - How to validate attachments names
Asked by Sopaboba:

Hi experts

I have checked all the questions related to attachments names and haven't found anything solving my problem.

Considering Confiforms doesn't support any kind of names changing on submitting the form, I am trying to validate the names instead and not letting the users to upload a file if doesn't match a certain name, built up with other fields.

It is pretty easy to force the user to upload a static name. Just have to set Validate rules in the field definition as, i.e., MYFILENAME.\* and everything works fine.

My problem starts when I am trying to do this dinamically. Let's say we have a field named USERNAME and I want to validate the name of the files setting up validation rules as \[entry.USERNAME\]. It is not working.

I have trying both in the field definition and setting rules for field definition and anything seems to work. I have tried using with and without \[\], also MyFileField.asAttachement.displayTitle:\[entry.USERNAME\], .fileName:\[entry.USERNAME\], \[entry.MyFileField.etc\]:USERNAME and all the possible combinations with those syntaxis. Nothing works.

Is there any way I can do that? Am I approaching this problem correctly?

Thanks for your help.


Answers:
author: Alex Medved _ConfiForms_
body: Hi

Pretty cryptic description and really difficult to understand what exactly is needed, but I will try. As it really is a pain to see when someone says "Nothing works"...

Validation rules conditions are described as ConfiForms filters - the syntax and how to write them (and logical explanation of the parts) you can see here <https://wiki.vertuna.com/display/CONFIFORMS/ConfiForms+Filters>

Please see the following demo

<http://recordit.co/18z8lMxSCF>

Hope it helps (and I got your requirements correctly)

Alex

comments: author: Sopaboba
body: Hi Alex

Sorry for the mess in my question. Even with the difficulties you could solve my problem and I am so thankful for that.

I am trying now to adapt it for several attachments (not only one).

Is it correct filtering like this:

!f.asAttachments.transform(displayTitle):\[entry.USERNAME\]\*

Because I have tried it like that and works if the first file is wrong, but not with the second and following files.

Again. Sorry for the mess. It is nos easy to explain yourself in a foreign language. I try to do my best but ...


author: Sopaboba
body: I made it work with this syntax:

!f.asAttachments.transform(displayTitle).asList:\[entry.USERNAME\], but there is only a problem:

1. When I upload several files at a time, and one ore more of them don't fit the rules, all the files are rejected, which is good, because I wan't all of them accepted if they fit the rules and force the user to try it again in case at least one of them is wrong.

2. When I upload several files at a time, and all of them fit the rules, they're all accepted, which is good.

3. When some files have been previously accepted and I modify the register by adding a new files, if this file doesn't fit the rules, it is accepted.

I can get by with what I've got, because this way I am forcing the user to use the names that I want, but in the third case the user could insert one file with a wrong name.

Anyway, it is working, because none of the users are uploading files in two or more steps. I am thinking about not letting them add more files and force them to clean all the register and start from the scratch if they want to add more files. That would be pretty easy, because I can empty the field f when the register is beeing modified and that's it.

Thank you for the tip, Alex, as always.

Regards.


author: Fabian Lim
body: adding [@Alex Medved _ConfiForms_](/t5/user/viewprofilepage/user-id/781630)


Tags: attachment

confiforms

confluence-server

server