Fixed accepted file types for file upload component.

Accept field is now optional and can be set for each usage of URLFieldWithFileUpload individually.
This commit is contained in:
Udo Wessels
2021-10-13 20:13:20 +02:00
parent 8597b9d898
commit 86fc8e4229
6 changed files with 13 additions and 11 deletions
@@ -65,11 +65,11 @@ public class URLFieldWithFileUpload extends Composite implements HasValue<String
private final FormPanel uploadFormPanel;
private final FlowPanel uploadPanel;
public URLFieldWithFileUpload(final StringMessages stringMessages) {
this(stringMessages, true, true);
public URLFieldWithFileUpload(final StringMessages stringMessages, String acceptedFileTypes) {
this(stringMessages, true, true, acceptedFileTypes);
}
public URLFieldWithFileUpload(final StringMessages stringMessages, boolean initiallyEnableUpload, boolean showUrlAfterUpload) {
public URLFieldWithFileUpload(final StringMessages stringMessages, boolean initiallyEnableUpload, boolean showUrlAfterUpload, String acceptedFileTypes) {
RESOURCES.urlFieldWithFileUploadStyle().ensureInjected();
startUploadEvent = new StartUploadEvent() {
@Override
@@ -131,7 +131,9 @@ public class URLFieldWithFileUpload extends Composite implements HasValue<String
uploadFormPanel.setEncoding(FormPanel.ENCODING_MULTIPART);
uploadFormPanel.setMethod(FormPanel.METHOD_POST);
fileUploadField = new FileUpload();
fileUploadField.getElement().setAttribute("accept", "audio/*,video/*");
if (acceptedFileTypes != null) {
fileUploadField.getElement().setAttribute("accept", acceptedFileTypes);
}
fileUploadField.setStylePrimaryName(RESOURCES.urlFieldWithFileUploadStyle().fileInputClass());
final InputElement inputElement = fileUploadField.getElement().cast();
inputElement.setName("file");