Skip to content

Commit f74d2c6

Browse files
devgurjardgurjar
andauthored
Date time input field (#1587)
* date time input field * date time fixes * Added test cases * fixed default message issue * fixed formatting * fixing code coverage * removed css and fixed formatting * Incorporated review comments * Added cypress tests on authoring and runtime --------- Co-authored-by: dgurjar <[email protected]>
1 parent f268f3e commit f74d2c6

File tree

50 files changed

+2080
-5
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2080
-5
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,8 @@ private FormConstants() {
151151

152152
/** The channel for print */
153153
public static final String CHANNEL_PRINT = "print";
154-
}
154+
155+
/** The resource type for date time input field v1 */
156+
public static final String RT_FD_FORM_DATETIME_V1 = RT_FD_FORM_PREFIX + "datetime/v1/datetime";
157+
158+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ private ReservedProperties() {
8686
public static final String PN_MAX_LENGTH = "maxLength";
8787
public static final String PN_MINIMUM_DATE = "minimumDate";
8888
public static final String PN_MAXIMUM_DATE = "maximumDate";
89+
public static final String PN_MINIMUM_DATE_TIME = "minimumDateTime";
90+
public static final String PN_MAXIMUM_DATE_TIME = "maximumDateTime";
8991
public static final String PN_MAXIMUM = "maximum";
9092
public static final String PN_MINIMUM = "minimum";
9193
public static final String PN_EXCLUSIVE_MINIMUM = "exclusiveMinimum";
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2+
~ Copyright 2025 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+
17+
package com.adobe.cq.forms.core.components.internal.models.v1.form;
18+
19+
import java.time.OffsetDateTime;
20+
import java.time.format.DateTimeFormatter;
21+
import java.util.Map;
22+
23+
import javax.annotation.Nullable;
24+
25+
import org.apache.sling.api.SlingHttpServletRequest;
26+
import org.apache.sling.api.resource.Resource;
27+
import org.apache.sling.models.annotations.Exporter;
28+
import org.apache.sling.models.annotations.Model;
29+
import org.apache.sling.models.annotations.injectorspecific.InjectionStrategy;
30+
import org.apache.sling.models.annotations.injectorspecific.ValueMapValue;
31+
import org.jetbrains.annotations.NotNull;
32+
33+
import com.adobe.cq.export.json.ComponentExporter;
34+
import com.adobe.cq.export.json.ExporterConstants;
35+
import com.adobe.cq.forms.core.components.internal.form.FormConstants;
36+
import com.adobe.cq.forms.core.components.models.form.*;
37+
import com.adobe.cq.forms.core.components.util.AbstractFieldImpl;
38+
import com.adobe.xfa.ut.StringUtils;
39+
import com.fasterxml.jackson.annotation.JsonFormat;
40+
41+
@Model(
42+
adaptables = { SlingHttpServletRequest.class, Resource.class },
43+
adapters = { DateTime.class, ComponentExporter.class },
44+
resourceType = { FormConstants.RT_FD_FORM_DATETIME_V1 })
45+
@Exporter(
46+
name = ExporterConstants.SLING_MODEL_EXPORTER_NAME,
47+
extensions = ExporterConstants.SLING_MODEL_EXTENSION)
48+
public class DateTimeImpl extends AbstractFieldImpl implements DateTime {
49+
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL)
50+
@Nullable
51+
private String pattern;
52+
53+
@Override
54+
public String getFieldType() {
55+
return super.getFieldType(FieldType.DATETIME_INPUT);
56+
}
57+
58+
@Override
59+
public String getMinimumDateTime() {
60+
return getFormattedDate(minimumDateTime);
61+
}
62+
63+
@Override
64+
public String getMaximumDateTime() {
65+
return getFormattedDate(maximumDateTime);
66+
}
67+
68+
private String getFormattedDate(String dateTime) {
69+
if (!StringUtils.isEmpty(dateTime)) {
70+
OffsetDateTime formattedTime = OffsetDateTime.parse(dateTime);
71+
return formattedTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm"));
72+
}
73+
return dateTime;
74+
75+
}
76+
77+
public @NotNull Map<ConstraintType, String> getConstraintMessages() {
78+
Map<ConstraintType, String> res = super.getConstraintMessages();
79+
String msg = getConstraintMessage(ConstraintType.MINIMUM);
80+
if (msg != null) {
81+
res.put(ConstraintType.MINIMUM, msg);
82+
}
83+
msg = getConstraintMessage(ConstraintType.MAXIMUM);
84+
if (msg != null) {
85+
res.put(ConstraintType.MAXIMUM, msg);
86+
}
87+
return res;
88+
}
89+
90+
@Override
91+
@Nullable
92+
public String getFormat() {
93+
return "date-time";
94+
}
95+
96+
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = Base.DATE_TIME_FORMATTER, timezone = "UTC")
97+
@Override
98+
public Object[] getDefault() {
99+
return defaultValue != null ? defaultValue.clone() : null;
100+
}
101+
102+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
public interface Base extends FormComponent {
3636
public final String DATE_FORMATTER = "yyyy-MM-dd";
3737

38+
public final String DATE_TIME_FORMATTER = "yyyy-MM-dd'T'HH:mm:ss";
39+
3840
/**
3941
* Constant representing the default language used, typically "en-US".
4042
*
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
/**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
~ Copyright 2025 Adobe
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
17+
18+
package com.adobe.cq.forms.core.components.models.form;
19+
20+
import org.osgi.annotation.versioning.ConsumerType;
21+
22+
/**
23+
* Interface for {@code Password} Sling Model used for the {@code /apps/core/fd/components/form/password/v1/password} component.
24+
*
25+
* @since com.adobe.cq.forms.core.components.models.form 5.12.0
26+
*/
27+
@ConsumerType
28+
public interface DateTime extends Field, DateTimeConstraint {
29+
30+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2+
~ Copyright 2025 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+
17+
package com.adobe.cq.forms.core.components.models.form;
18+
19+
import com.fasterxml.jackson.annotation.JsonFormat;
20+
import com.fasterxml.jackson.annotation.JsonInclude;
21+
import com.fasterxml.jackson.annotation.JsonProperty;
22+
23+
public interface DateTimeConstraint extends FormatConstraint {
24+
/**
25+
* Returns the minimum value for the date. The constraint is applicable only for field with type date
26+
*
27+
* @return minimum date
28+
* @since com.adobe.cq.forms.core.components.models.form 5.11.0
29+
*/
30+
@JsonInclude(JsonInclude.Include.NON_NULL)
31+
@JsonProperty("minimum")
32+
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = Base.DATE_TIME_FORMATTER, timezone = "UTC")
33+
String getMinimumDateTime();
34+
35+
/**
36+
* Returns the maximum value for the date. The constraint is applicable only for field with type date
37+
*
38+
* @return maximum date
39+
* @since com.adobe.cq.forms.core.components.models.form 5.11.0
40+
*/
41+
@JsonInclude(JsonInclude.Include.NON_NULL)
42+
@JsonProperty("maximum")
43+
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = Base.DATE_TIME_FORMATTER, timezone = "UTC")
44+
String getMaximumDateTime();
45+
46+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public enum FieldType {
3838
IMAGE("image"),
3939
TELEPHONE("tel"),
4040
PASSWORD("password"),
41+
DATETIME_INPUT("datetime-input"),
4142
RANGE("range"),
4243
COLOR("color"),
4344
URL("url"),

bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/util/AbstractFieldImpl.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,14 @@ public static EmptyValue fromString(String value) {
132132
@Nullable
133133
protected Date maximumDate;
134134

135+
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = ReservedProperties.PN_MINIMUM_DATE_TIME)
136+
@Nullable
137+
protected String minimumDateTime;
138+
139+
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = ReservedProperties.PN_MAXIMUM_DATE_TIME)
140+
@Nullable
141+
protected String maximumDateTime;
142+
135143
/** Do not do any changes, this is just present for backward compatibility **/
136144
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = ReservedProperties.PN_MAXIMUM)
137145
@Nullable

0 commit comments

Comments
 (0)