Error with requiredFields() and setFieldUpload()

Hi,

I am using setFieldUpload() to manage a table of images, and I mark the first parameter (File Name) as required (“image”). I undestand that it is obvious to have “required field” there.

However, if I did this I get an error when I save (" * Image is required").

I suppose it is a bug, any help?

Thanks in advance.

Hello @Alberto

Yes this seems like a bug. I will try to fix it for the next version release.

Regards
Johnny

Thanks Johnny for your fast answer, and I am very proud to help improve GC.

I have been doing some tests with the fuction setFieldUpload() and I think I found some issues as well. I will try to explain by points:

1.- lf you upload one file with the same name than an existing one (it can be the same file or not); GC upload and register it with a modified name adding some random alpha-numeric code at the end of the name. I understand that this behaviour is “coherent” however I would like to have any type of “alarm-message” to inform me about that.

2.- In my case… I need to have different registers in the database that point to the same file (an image in my case), so Point 1 behaviour can be a problem. However, I have found a solution, if it is used the “Clone” function from an existing register it is possible to have two (or more) registers point to the same file. Maybe my case is not really common, and to have the posibility of doing it thru “Clone” function can be supposed as a bug.

3.- Once I get some registers pointing to the same file (using “Clone”); if I set the configuration with “‘remove_file_on_delete’ => true,” if one of this registers is deleted the file is deleted without checking that there are others registers that point to the same file. You can cosider this a bug or you can cosider “Point 2 - Clone register” behaviour a bug…

So… I was thinking about it, and I propose the following solution (however it can be others or it can be left as it is now as well…):

1.- To implement a checking in the deletion of the files: Before deleting the file, it is needed to check if there is other register that point this file. The deletion is done only if there is no other register pointing the same file.

2.- To implement a “multi_file_register” parameter in configuration (or in setFieldUpload() funtion) in order to control the behaviour for “already existing files”. The possible behaviour can be:

If “multi_file_register” is set to TRUE:

  • When a file with the same name than existing one is upload: The register is done however the file is not upload. A message informing of this behaviour would be apreciated, maybe a “perfect behaviour” would be a checking-comparison between the two files and to see if they are really the same file or different files with the same name (I don’t know if this can be complicated)

  • When it is clone a register with the same file name: the register is done without no problem.

  • When it is deleted a register with “‘remove_file_on_delete’ => true,”: The file is deleted only if there is no other register pointing the file.

If “multi_file_register” is set to FALSE:

  • When a file with the same name than existing one is upload: The file is upload but with a updated name (as it is happening now). A message informing of this behaviour would be apreciated.

  • When it is clone a register with the same file name: An error message will appear informing that a file with this file already exists.

  • When it is deleted a register with “‘remove_file_on_delete’ => true,”: The file is deleted directly (we now that it is the only register).

Ok… so that’s all… I hope this post help to improve, however I know that can be other possible solutions, I try to do it in the way that different desired behaviours can be attendended. Of course other possible it is that everyone adapt the program with different callbacks funtions.

Regards,

Alberto

Hello @Alberto ,

I’ve fixed the issue with the required fields and upload for the next release version. The next release will be probably delayed a bit more due to some testing that I have done since I’ve refactored the $crud->where statement quite a lot (so we can have multiple where statements)

Now for the rest I believe that this is more or less something unique for your project. Yes, the bugs that you’ve referred sounds to me as bugs so I will have them a look whenever I have some time. But for you I believe that using callbackUpload will help you have some if statements on every upload.

I have updated also the documentation with a working example here: callbackUpload | Grocery CRUD v3

Let me know if that helped.

Regards
Johnny

Hello @Alberto ,

I am glad to inform you that the requiredFields now work as expected with setFieldUpload and setFieldUploadMultiple on the latest version (3.0.10) . That I’ve just released. You can download the latest version from the wizard: User's Page Login

Regards
Johnny

Hi Johnny,

I have no time to check until this weekend. Really thanks for taking care of the bug.

Regards

Alberto

1 Like