Skip to content

Commit 6f2ba76

Browse files
drag and dropp intial commit
removed commented code test case for drag and drop added
1 parent 069b503 commit 6f2ba76

File tree

22 files changed

+1225
-3
lines changed

22 files changed

+1225
-3
lines changed

bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/internal/form/FormConstants.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ private FormConstants() {
6565
/** The resource type for file input v1 */
6666
public static final String RT_FD_FORM_FILE_INPUT_V1 = RT_FD_FORM_PREFIX + "fileinput/v1/fileinput";
6767

68+
/** The resource type for file input v2 */
69+
public static final String RT_FD_FORM_FILE_INPUT_V2 = RT_FD_FORM_PREFIX + "fileinput/v2/fileinput";
70+
6871
/** The resource type for check box group v1 */
6972
public static final String RT_FD_FORM_CHECKBOX_GROUP_V1 = RT_FD_FORM_PREFIX + "checkboxgroup/v1/checkboxgroup";
7073

bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/internal/models/v1/form/FileInputImpl.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.util.Arrays;
1919
import java.util.Collections;
2020
import java.util.List;
21+
import java.util.Map;
2122
import java.util.Optional;
2223

2324
import org.apache.sling.api.SlingHttpServletRequest;
@@ -27,6 +28,7 @@
2728
import org.apache.sling.models.annotations.Model;
2829
import org.apache.sling.models.annotations.injectorspecific.InjectionStrategy;
2930
import org.apache.sling.models.annotations.injectorspecific.ValueMapValue;
31+
import org.jetbrains.annotations.NotNull;
3032

3133
import com.adobe.cq.export.json.ComponentExporter;
3234
import com.adobe.cq.export.json.ExporterConstants;
@@ -38,14 +40,19 @@
3840
adaptables = { SlingHttpServletRequest.class, Resource.class },
3941
adapters = { FileInput.class,
4042
ComponentExporter.class },
41-
resourceType = { FormConstants.RT_FD_FORM_FILE_INPUT_V1 })
43+
resourceType = { FormConstants.RT_FD_FORM_FILE_INPUT_V2 })
4244
@Exporter(name = ExporterConstants.SLING_MODEL_EXPORTER_NAME, extensions = ExporterConstants.SLING_MODEL_EXTENSION)
4345
public class FileInputImpl extends AbstractFieldImpl implements FileInput {
4446

47+
private static final String FILE_INPUT_DRAG_DROP_TEXT = "fileInputDragDropText";
48+
4549
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = "multiSelection")
4650
@Default(booleanValues = false)
4751
protected boolean multiSelection;
4852

53+
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = "fileInputDragDropText")
54+
protected String fileInputDragDropText;
55+
4956
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = "maxFileSize")
5057
protected String maxFileSize;
5158

@@ -56,6 +63,10 @@ public class FileInputImpl extends AbstractFieldImpl implements FileInput {
5663
@Default(values = FileInput.DEFAULT_BUTTON_TEXT)
5764
protected String buttonText;
5865

66+
public String getFileInputDragDropText() {
67+
return fileInputDragDropText;
68+
}
69+
5970
@Override
6071
public Integer getMinItems() {
6172
return minItems;
@@ -102,4 +113,11 @@ public List<String> getAccept() {
102113
.map(Arrays::asList)
103114
.orElse(Collections.emptyList());
104115
}
116+
117+
@Override
118+
public @NotNull Map<String, Object> getProperties() {
119+
Map<String, Object> customProperties = super.getProperties();
120+
customProperties.put(FILE_INPUT_DRAG_DROP_TEXT, getFileInputDragDropText());
121+
return customProperties;
122+
}
105123
}

examples/ui.apps/src/main/content/jcr_root/apps/forms-components-examples/components/form/fileinput/.content.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
jcr:primaryType="cq:Component"
44
jcr:title="Adaptive Form File Attachment"
55
jcr:description="Add a button to upload one or more files as form attachment."
6-
sling:resourceSuperType="core/fd/components/form/fileinput/v1/fileinput"
6+
sling:resourceSuperType="core/fd/components/form/fileinput/v2/fileinput"
77
componentGroup="Core Components Examples - Adaptive Form"/>

examples/ui.apps/src/main/content/jcr_root/apps/forms-components-examples/components/form/fileinput/_cq_template.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
jcr:title="File Attachment"
55
buttonText="Attach"
66
fieldType="file-input"
7+
fileInputDragDropText="Drag and drop to Upload"
78
accept="[audio/*, video/*, image/*, text/*, application/pdf]">
89
</jcr:root>

ui.af.apps/src/main/content/jcr_root/apps/core/fd/af-clientlibs/core-forms-components-runtime-all/.content.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
cssProcessor="[default:none,min:none]"
66
jsProcessor="[default:none,min:none]"
77
categories="[core.forms.components.runtime.all]"
8-
embed="[core.forms.components.runtime.base,core.forms.components.container.v2.runtime,core.forms.components.datePicker.v1.runtime,core.forms.components.textinput.v1.runtime,core.forms.components.numberinput.v1.runtime,core.forms.components.panelcontainer.v1.runtime,core.forms.components.radiobutton.v1.runtime,core.forms.components.text.v1.runtime,core.forms.components.checkboxgroup.v1.runtime,core.forms.components.button.v1.runtime,core.forms.components.image.v1.runtime,core.forms.components.dropdown.v1.runtime,core.forms.components.fileinput.v1.runtime,core.forms.components.accordion.v1.runtime,core.forms.components.tabs.v1.runtime,core.forms.components.wizard.v1.runtime,core.forms.components.verticaltabs.v1.runtime,core.forms.components.recaptcha.v1.runtime,core.forms.components.checkbox.v1.runtime,core.forms.components.fragment.v1.runtime,core.forms.components.switch.v1.runtime,core.forms.components.termsandconditions.v1.runtime]"/>
8+
embed="[core.forms.components.runtime.base,core.forms.components.container.v2.runtime,core.forms.components.datePicker.v1.runtime,core.forms.components.textinput.v1.runtime,core.forms.components.numberinput.v1.runtime,core.forms.components.panelcontainer.v1.runtime,core.forms.components.radiobutton.v1.runtime,core.forms.components.text.v1.runtime,core.forms.components.checkboxgroup.v1.runtime,core.forms.components.button.v1.runtime,core.forms.components.image.v1.runtime,core.forms.components.dropdown.v1.runtime,core.forms.components.fileinput.v2.runtime,core.forms.components.accordion.v1.runtime,core.forms.components.tabs.v1.runtime,core.forms.components.wizard.v1.runtime,core.forms.components.verticaltabs.v1.runtime,core.forms.components.recaptcha.v1.runtime,core.forms.components.checkbox.v1.runtime,core.forms.components.fragment.v1.runtime,core.forms.components.switch.v1.runtime,core.forms.components.termsandconditions.v1.runtime]"/>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
3+
jcr:primaryType="nt:unstructured">
4+
<fileinput/>
5+
</jcr:root>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
3+
cq:icon="attach"
4+
jcr:primaryType="cq:Component"
5+
jcr:title="Adaptive Form File Attachment (v2)"
6+
jcr:description="Add a button to upload one or more files as form attachment."
7+
sling:resourceSuperType="core/fd/components/form/base/v1/base"
8+
componentGroup=".core-adaptiveform"/>
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<!--
2+
Copyright 2022 Adobe
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
Adaptive Form File Input (v2)
17+
====
18+
Adaptive Form File input field component written in HTL.
19+
20+
## Features
21+
22+
* Drag and drop support
23+
* Custom icon for drag and drop
24+
* Provides the following type of input:
25+
* file
26+
* Custom constraint messages for the above types
27+
* Styles
28+
29+
### Use Object
30+
The Form File component uses the `com.adobe.cq.forms.core.components.models.form.FileInput` Sling Model for its Use-object.
31+
32+
### Edit Dialog Properties
33+
The following properties are written to JCR for this Form File component and are expected to be available as `Resource` properties:
34+
35+
1. `./jcr:title` - defines the label to use for this field
36+
2. `./hideTitle` - if set to `true`, the label of this field will be hidden
37+
3. `./name` - defines the name of the field, which will be submitted with the form data
38+
4. `./default` - defines the default value of the field
39+
5. `./description` - defines a help message that can be rendered in the field as a hint for the user
40+
6. `./required` - if set to `true`, this field will be marked as required, not allowing the form to be submitted until the field has a value
41+
7. `./requiredMessage` - defines the message displayed as tooltip when submitting the form if the value is left empty
42+
8. `./readOnly` - if set to `true`, the filed will be read only
43+
9. `./multiSelection` - if set to `true`, the filed will allow to add multiple files in single selection or multiple selections
44+
10. `./minItems` - if value is selected/provided this will check for minimum number of files that can be attached
45+
11. `./maxItems` - if value is selected/provided this will check for maximum number of files that can be attached
46+
12. `./maxFileSize` - if value is selected/provided this will check for maximum file size allowed
47+
13. `./accept` - defines the type of files accepted to upload
48+
14. `./showComment` - if set to `true`, comments can be added to attachment
49+
15. `./minItemsMessage` - defines the message displayed as tooltip when submitting the form if less than allowed minimum files uploaded
50+
16. `./maxItemsMessage` - defines the message displayed as tooltip when submitting the form if more than allowed maximum files uploaded
51+
17. `./maxFileSizeMessage` - defines the message displayed as tooltip when submitting the form if the uploaded file size is greater than allowed
52+
18. `./acceptMessage` - defines the message displayed as tooltip when submitting the form if the uploaded file type is not allowed
53+
54+
## Client Libraries
55+
The component provides a `core.forms.components.fileinput.v2.runtime` client library category that contains the Javascript runtime for the component.
56+
It should be added to a relevant site client library using the `embed` property.
57+
58+
It also provides a `core.forms.components.fileinput.v2.editor` editor client library category that includes
59+
JavaScript handling for dialog interaction. It is already included by its edit dialog.
60+
61+
## BEM Description
62+
```
63+
BLOCK cmp-adaptiveform-fileinput
64+
ELEMENT cmp-adaptiveform-fileinput__label
65+
ELEMENT cmp-adaptiveform-fileinput__label-container
66+
ELEMENT cmp-adaptiveform-fileinput__widget
67+
ELEMENT cmp-adaptiveform-fileinput__questionmark
68+
ELEMENT cmp-adaptiveform-fileinput__shortdescription
69+
ELEMENT cmp-adaptiveform-fileinput__longdescription
70+
ELEMENT cmp-adaptiveform-fileinput__filelist
71+
ELEMENT cmp-adaptiveform-fileinput__fileitem
72+
ELEMENT cmp-adaptiveform-fileinput__filename
73+
ELEMENT cmp-adaptiveform-fileinput__filedelete
74+
ELEMENT cmp-adaptiveform-fileinput__widgetlabel
75+
```
76+
77+
### Note
78+
By placing the class names `cmp-adaptiveform-fileinput__label` and `cmp-adaptiveform-fileinput__questionmark` within the `cmp-adaptiveform-fileinput__label-container` class, you create a logical grouping of the label and question mark elements. This approach simplifies the process of maintaining a consistent styling for both elements.
79+
80+
## JavaScript Data Attribute Bindings
81+
82+
83+
The following attributes must be added for the initialization of the file-input component in the form view:
84+
1. `data-cmp-is="adaptiveFormFileInput"`
85+
2. `data-cmp-adaptiveformcontainer-path="${formstructparser.formContainerPath}"`
86+
87+
88+
## Information
89+
* **Vendor**: Adobe
90+
* **Version**: v2
91+
* **Compatibility**: Cloud
92+
* **Status**: production-ready
93+

0 commit comments

Comments
 (0)