diff --git a/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/internal/models/v1/form/FileInputImpl.java b/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/internal/models/v1/form/FileInputImpl.java index 4e059e97b0..1753357a3c 100644 --- a/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/internal/models/v1/form/FileInputImpl.java +++ b/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/internal/models/v1/form/FileInputImpl.java @@ -21,6 +21,7 @@ import java.util.Map; import java.util.Optional; +import org.apache.commons.lang3.StringUtils; import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.resource.Resource; import org.apache.sling.models.annotations.Default; @@ -72,12 +73,23 @@ public Integer getMaxItems() { @Override public Type getType() { - // file upload does not work for type string in core component, hence default it to file - if (!isMultiple()) { - return Type.FILE; - } else { - return Type.FILE_ARRAY; + Type superType = super.getType(); + if (superType == null || StringUtils.isBlank(typeJcr) || superType == Type.FILE) { + return isMultiple() ? Type.FILE_ARRAY : Type.FILE; } + if (isMultiple() && superType == Type.STRING) { + return Type.STRING_ARRAY; + } + return superType; + } + + @Override + public String getFormat() { + Type type = getType(); + if (type == Type.STRING || type == Type.STRING_ARRAY) { + return "data-url"; + } + return null; } @Override diff --git a/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/models/form/FileConstraint.java b/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/models/form/FileConstraint.java index 68e87b9150..9b53a9632c 100644 --- a/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/models/form/FileConstraint.java +++ b/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/models/form/FileConstraint.java @@ -21,6 +21,8 @@ import org.osgi.annotation.versioning.ProviderType; +import com.fasterxml.jackson.annotation.JsonInclude; + /** * Interface for constraints applicable to file attachments * @@ -54,4 +56,15 @@ default String getMaxFileSize() { default List getAccept() { return DEFAULT_ACCEPT; } + + /** + * The constraint is + * applicable for file attachment field. If the type is {@code String}, the format will always be {@code data-url}. + * + * @since com.adobe.cq.forms.core.components.models.form 5.7.4 + */ + @JsonInclude(JsonInclude.Include.NON_NULL) + default String getFormat() { + return null; + } } diff --git a/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/models/form/package-info.java b/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/models/form/package-info.java index c06f9a92e7..b0e57e0089 100644 --- a/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/models/form/package-info.java +++ b/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/models/form/package-info.java @@ -35,7 +35,7 @@ *

*/ -@Version("5.6.4") +@Version("5.7.4") package com.adobe.cq.forms.core.components.models.form; import org.osgi.annotation.versioning.Version; diff --git a/bundles/af-core/src/test/java/com/adobe/cq/forms/core/components/internal/models/v1/form/FileInputImplTest.java b/bundles/af-core/src/test/java/com/adobe/cq/forms/core/components/internal/models/v1/form/FileInputImplTest.java index 3de57ce01e..7a0a812b69 100644 --- a/bundles/af-core/src/test/java/com/adobe/cq/forms/core/components/internal/models/v1/form/FileInputImplTest.java +++ b/bundles/af-core/src/test/java/com/adobe/cq/forms/core/components/internal/models/v1/form/FileInputImplTest.java @@ -59,6 +59,7 @@ public class FileInputImplTest { private static final String PATH_FILEINPUT_DATALAYER = CONTENT_ROOT + "/fileinput-datalayer"; private static final String PATH_MULTISELECT_FILEINPUT = CONTENT_ROOT + "/multiselect-fileinput"; private static final String PATH_MULTISELECT_FILEINPUT_WITHNOTYPE = CONTENT_ROOT + "/multiselect-fileinput-withNoType"; + private static final String PATH_MULTISELECT_FILEINPUT_WITH_TYPE = CONTENT_ROOT + "/fileInput-withType"; private static final String PATH_FILEINPUT_WITHOUT_FIELDTYPE = CONTENT_ROOT + "/fileinput-without-fieldtype"; private final AemContext context = FormsCoreComponentTestContext.newAemContext(); @@ -86,7 +87,13 @@ void testFieldType() { @Test void testType() { FileInput fileInput = Utils.getComponentUnderTest(PATH_MULTISELECT_FILEINPUT_WITHNOTYPE, FileInput.class, context); - assertEquals(fileInput.getType(), fileInput.getType()); + assertEquals(BaseConstraint.Type.FILE_ARRAY, fileInput.getType()); + } + + @Test + void testStringType() { + FileInput fileInput = Utils.getComponentUnderTest(PATH_MULTISELECT_FILEINPUT_WITH_TYPE, FileInput.class, context); + assertEquals(BaseConstraint.Type.STRING_ARRAY, fileInput.getType()); } @Test diff --git a/bundles/af-core/src/test/resources/form/fileinput/test-content.json b/bundles/af-core/src/test/resources/form/fileinput/test-content.json index e40420b116..671eb298b8 100644 --- a/bundles/af-core/src/test/resources/form/fileinput/test-content.json +++ b/bundles/af-core/src/test/resources/form/fileinput/test-content.json @@ -102,6 +102,26 @@ "maxFileSize" : "4096", "accept" : ["text/*", "application/pdf"] }, + "fileInput-withType": { + "jcr:primaryType": "nt:unstructured", + "sling:resourceType" : "core/fd/components/form/fileinput/v1/fileinput", + "fieldType": "file-input", + "name" : "abc", + "jcr:title" : "def", + "description" : "dummy", + "visible" : false, + "assistPriority" : "custom", + "dataRef" : "a.b", + "custom" : "Custom screen reader text", + "typeMessage" : "incorrect type", + "tooltip": "test-short-description", + "multiSelection" : true, + "type" : "string", + "minItems" : 1, + "maxItems" : 2, + "maxFileSize" : "4096", + "accept" : ["text/*", "application/pdf"] + }, "fileinput-without-fieldtype": { "jcr:primaryType": "nt:unstructured", "sling:resourceType" : "core/fd/components/form/fileinput/v1/fileinput", diff --git a/it/apps/src/main/content/jcr_root/apps/forms-core-components-it/components/page-fileinputv3/customfooterlibs.html b/it/apps/src/main/content/jcr_root/apps/forms-core-components-it/components/page-fileinputv3/customfooterlibs.html index 4e75eebfc8..303e22ea40 100644 --- a/it/apps/src/main/content/jcr_root/apps/forms-core-components-it/components/page-fileinputv3/customfooterlibs.html +++ b/it/apps/src/main/content/jcr_root/apps/forms-core-components-it/components/page-fileinputv3/customfooterlibs.html @@ -20,7 +20,7 @@ - + diff --git a/it/content/src/main/content/jcr_root/content/dam/formsanddocuments/core-components-it/samples/fileinput/fileinputstring/.content.xml b/it/content/src/main/content/jcr_root/content/dam/formsanddocuments/core-components-it/samples/fileinput/fileinputstring/.content.xml new file mode 100755 index 0000000000..7256712059 --- /dev/null +++ b/it/content/src/main/content/jcr_root/content/dam/formsanddocuments/core-components-it/samples/fileinput/fileinputstring/.content.xml @@ -0,0 +1,7 @@ + + diff --git a/it/content/src/main/content/jcr_root/content/dam/formsanddocuments/core-components-it/samples/fileinput/fileinputstring/basic/.content.xml b/it/content/src/main/content/jcr_root/content/dam/formsanddocuments/core-components-it/samples/fileinput/fileinputstring/basic/.content.xml new file mode 100755 index 0000000000..d69958e530 --- /dev/null +++ b/it/content/src/main/content/jcr_root/content/dam/formsanddocuments/core-components-it/samples/fileinput/fileinputstring/basic/.content.xml @@ -0,0 +1,23 @@ + + + + + + \ No newline at end of file diff --git a/it/content/src/main/content/jcr_root/content/forms/af/core-components-it/samples/fileinput/fileinputstring/.content.xml b/it/content/src/main/content/jcr_root/content/forms/af/core-components-it/samples/fileinput/fileinputstring/.content.xml new file mode 100644 index 0000000000..bbf62ed22c --- /dev/null +++ b/it/content/src/main/content/jcr_root/content/forms/af/core-components-it/samples/fileinput/fileinputstring/.content.xml @@ -0,0 +1,5 @@ + +