Solution to set an image as mandatory

Hello Team,

I Have an entity with a mandatory FileDescriptor attribute named logo, by default the framework doesn’t support Images, so i had to do the solution described in Loading and Displaying Images , but the problem is that the attribute is still in the field group after adding the image so i wanted to remove it as after applying the solution i have a proper image with an upload button.
When i removed it and in case i didn’t upload an image before saving the screen the database not null constraint kicked in which looks ugly :), I tried the following to solve this with no success:

  • Removing the Attribute from the field group --> Not null database error message.
  • Keeping the attribute in the screen --> Error Message is displayed properly but the attribute doesn’t make sense in the screen as i have the image and the upload button.
  • checking the Hidden flag of the field --> the whole attribute didn’t get generated in the HTML and the database error kicked in when saving.
  • Entering “type=hidden” in the other field in the field editor of the Cuba IDE, but nothing got hidden in the generated HTML.

Is there a way to keep the image with the upload button and remove the FileDescriptor attribute and also have a proper error message displayed to the user in case the user tried to save without selecting an image…

Hi,

Take a look at the postValidate method, it should solve your issue.

Regards,
Gleb

1 Like