withRequired() on custom parameter not working & how to increase maximum size on fileparameter

I created a dialog and ran into 2 issues

  1. if you use InputParameter.fileParamer()… I found no option to set the maximum filesize so I had to resort to using a custom parameter
  2. if you use a custom parameter. the .withRequired(true) on the Inputparameter is
    ignored, instead you have to have an extra setRequired(true) on the field declaration. No idea if this could be improved but it was misleading.
        dialogs.createInputDialog(this)
                .withHeader("Import theoretical maintenance schedule as .csv")
                .withParameters(
                        InputParameter.stringParameter("name").withLabel("Name").withRequired(true),
                        InputParameter.parameter("file")
                                .withRequired(true)   //  IGNORED
                                .withLabel("File")
                                .withField(() -> {
                                    FileUploadField field = uiComponents.create(FileUploadField.class);
                                    field.setAcceptedFileTypes(".csv");
                                    field.setMaxFileSize(TWENTY_MEGABYTE);
                                    field.setRequired(true);   // WORKING
                                    return field;
                                })
                )

Hi,

This is correct behaviour. When you define a custom field, you need to use its API directly.

Regards,
Gleb

1 Like