Skip to content

Commit b1743af

Browse files
author
dgurjar
committed
date time input field
1 parent 1ec18f1 commit b1743af

File tree

34 files changed

+1253
-1
lines changed

34 files changed

+1253
-1
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ private FormConstants() {
137137

138138
public static final String PROP_FRAGMENT_PATH = "fragmentPath";
139139

140+
<<<<<<< HEAD
140141
/** The resource type for review v1 */
141142
public static final String RT_FD_FORM_REVIEW_V1 = RT_FD_FORM_PREFIX + "review/v1/review";
142143

@@ -148,4 +149,5 @@ private FormConstants() {
148149

149150
/** Form definition type indicating submission view */
150151
public static final String FORM_DEFINITION_SUBMISSION = "submission";
152+
public static final String RT_FD_FORM_DATETIME_V1 = RT_FD_FORM_PREFIX + "datetime/v1/datetime";
151153
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2+
~ Copyright 2024 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 javax.annotation.Nullable;
20+
import javax.annotation.PostConstruct;
21+
22+
import org.apache.sling.api.SlingHttpServletRequest;
23+
import org.apache.sling.api.resource.Resource;
24+
import org.apache.sling.models.annotations.Exporter;
25+
import org.apache.sling.models.annotations.Model;
26+
import org.apache.sling.models.annotations.injectorspecific.InjectionStrategy;
27+
import org.apache.sling.models.annotations.injectorspecific.ValueMapValue;
28+
29+
import com.adobe.cq.export.json.ComponentExporter;
30+
import com.adobe.cq.export.json.ExporterConstants;
31+
import com.adobe.cq.forms.core.components.internal.form.FormConstants;
32+
import com.adobe.cq.forms.core.components.models.form.DateTime;
33+
import com.adobe.cq.forms.core.components.util.AbstractFieldImpl;
34+
import com.adobe.cq.forms.core.components.util.ComponentUtils;
35+
36+
@Model(
37+
adaptables = { SlingHttpServletRequest.class, Resource.class },
38+
adapters = { DateTime.class, ComponentExporter.class },
39+
resourceType = { FormConstants.RT_FD_FORM_DATETIME_V1 })
40+
@Exporter(
41+
name = ExporterConstants.SLING_MODEL_EXPORTER_NAME,
42+
extensions = ExporterConstants.SLING_MODEL_EXTENSION)
43+
public class DateTimeImpl extends AbstractFieldImpl implements DateTime {
44+
45+
private Object exclusiveMinimumVaue;
46+
private Object exclusiveMaximumValue;
47+
48+
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL)
49+
@Nullable
50+
private String pattern;
51+
52+
@Override
53+
public String getFieldType() {
54+
return super.getFieldType();
55+
}
56+
57+
@Override
58+
public Integer getMinLength() {
59+
return minLength;
60+
}
61+
62+
@Override
63+
public Integer getMaxLength() {
64+
return maxLength;
65+
}
66+
67+
@Override
68+
public Long getMinimum() {
69+
return minimum;
70+
}
71+
72+
@Override
73+
public Long getMaximum() {
74+
return maximum;
75+
}
76+
77+
@Override
78+
public String getFormat() {
79+
return displayFormat;
80+
}
81+
82+
@Override
83+
public String getPattern() {
84+
return pattern;
85+
}
86+
87+
@Override
88+
public Long getExclusiveMaximum() {
89+
return (Long) exclusiveMaximumValue;
90+
}
91+
92+
@Override
93+
public Long getExclusiveMinimum() {
94+
return (Long) exclusiveMinimumVaue;
95+
}
96+
97+
@PostConstruct
98+
private void initTextInput() {
99+
exclusiveMaximumValue = ComponentUtils.getExclusiveValue(exclusiveMaximum, maximum, null);
100+
exclusiveMinimumVaue = ComponentUtils.getExclusiveValue(exclusiveMinimum, minimum, null);
101+
// in json either, exclusiveMaximum or maximum should be present
102+
if (exclusiveMaximumValue != null) {
103+
maximum = null;
104+
}
105+
if (exclusiveMinimumVaue != null) {
106+
minimum = null;
107+
}
108+
}
109+
110+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
/**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
~ Copyright 2024 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 2.0.0
26+
*/
27+
@ConsumerType
28+
public interface DateTime extends Field, StringConstraint, NumberConstraint {
29+
30+
/**
31+
* Returns the validation pattern (regex) for the password field.
32+
*
33+
* @return the validation pattern
34+
* @since com.adobe.cq.forms.core.components.models.form 2.0.0
35+
*/
36+
String getPattern();
37+
38+
}

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("date-time"),
4142
RANGE("range"),
4243
COLOR("color"),
4344
URL("url"),
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2+
~ Copyright 2024 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 org.apache.commons.lang3.reflect.FieldUtils;
20+
import org.junit.jupiter.api.BeforeEach;
21+
import org.junit.jupiter.api.Test;
22+
import org.junit.jupiter.api.extension.ExtendWith;
23+
24+
import com.adobe.cq.forms.core.Utils;
25+
import com.adobe.cq.forms.core.components.datalayer.FormComponentData;
26+
import com.adobe.cq.forms.core.components.models.form.DateTime;
27+
import com.adobe.cq.forms.core.components.models.form.FieldType;
28+
import com.adobe.cq.forms.core.context.FormsCoreComponentTestContext;
29+
import io.wcm.testing.mock.aem.junit5.AemContext;
30+
import io.wcm.testing.mock.aem.junit5.AemContextExtension;
31+
32+
import static org.junit.Assert.assertEquals;
33+
import static org.junit.Assert.assertNull;
34+
35+
@ExtendWith(AemContextExtension.class)
36+
public class DateTimeImplTest {
37+
38+
private static final String BASE = "/form/datetime";
39+
private static final String CONTENT_ROOT = "/content";
40+
private static final String PATH_DATETIME_DATALAYER = CONTENT_ROOT + "/datetime-datalayer";
41+
private static final String PATH_DATETIME_CUSTOMIZED = CONTENT_ROOT + "/datetime-customized";
42+
private static final String PATH_NUMBER_DATETIME_EXCLUSIVE = CONTENT_ROOT + "/number-datetime-exclusive";
43+
private static final String PATH_NUMBER_DATETIME_INPUT = CONTENT_ROOT + "/number-datetime";
44+
45+
private final AemContext context = FormsCoreComponentTestContext.newAemContext();
46+
47+
@BeforeEach
48+
void setUp() {
49+
context.load().json(BASE + FormsCoreComponentTestContext.TEST_CONTENT_JSON, CONTENT_ROOT);
50+
}
51+
52+
@Test
53+
void testFieldType() {
54+
DateTime dateTime = Utils.getComponentUnderTest(PATH_DATETIME_CUSTOMIZED, DateTime.class, context);
55+
assertEquals(FieldType.DATETIME.getValue(), dateTime.getFieldType());
56+
}
57+
58+
@Test
59+
void testGetLabel() {
60+
DateTime dateTime = Utils.getComponentUnderTest(PATH_DATETIME_CUSTOMIZED, DateTime.class, context);
61+
assertEquals("pwd", dateTime.getLabel().getValue());
62+
}
63+
64+
@Test
65+
void testPlaceholder() {
66+
DateTime dateTime = Utils.getComponentUnderTest(PATH_DATETIME_CUSTOMIZED, DateTime.class, context);
67+
assertEquals("Enter valid date & time", dateTime.getPlaceHolder());
68+
}
69+
70+
@Test
71+
void testGetName() {
72+
DateTime datetime = Utils.getComponentUnderTest(PATH_DATETIME_CUSTOMIZED, DateTime.class, context);
73+
assertEquals("datetime", datetime.getName());
74+
75+
}
76+
77+
@Test
78+
void testDorProperties() {
79+
DateTime datetime = Utils.getComponentUnderTest(PATH_DATETIME_CUSTOMIZED, DateTime.class, context);
80+
assertEquals(true, datetime.getDorProperties().get("dorExclusion"));
81+
assertEquals("4", datetime.getDorProperties().get("dorColspan"));
82+
assertEquals("Text1", datetime.getDorProperties().get("dorBindRef"));
83+
84+
}
85+
86+
@Test
87+
void testGetDescription() {
88+
DateTime datetime = Utils.getComponentUnderTest(PATH_DATETIME_CUSTOMIZED, DateTime.class, context);
89+
assertEquals("datetime field", datetime.getDescription());
90+
}
91+
92+
@Test
93+
void testGetRequired() {
94+
DateTime datetime = Utils.getComponentUnderTest(PATH_DATETIME_CUSTOMIZED, DateTime.class, context);
95+
assertEquals(true, datetime.isRequired());
96+
}
97+
98+
@Test
99+
void testGetPattern() {
100+
DateTime datetime = Utils.getComponentUnderTest(PATH_DATETIME_CUSTOMIZED, DateTime.class, context);
101+
assertEquals("/^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[a-zA-Z]).{8,}$/", datetime.getPattern());
102+
103+
}
104+
105+
@Test
106+
void testIsEnabled() {
107+
DateTime datetime = Utils.getComponentUnderTest(PATH_DATETIME_CUSTOMIZED, DateTime.class, context);
108+
assertEquals(true, datetime.isEnabled());
109+
}
110+
111+
@Test
112+
void testIsEnabledForCustomized() {
113+
DateTime datetime = Utils.getComponentUnderTest(PATH_DATETIME_CUSTOMIZED, DateTime.class, context);
114+
assertEquals(true, datetime.isEnabled());
115+
}
116+
117+
@Test
118+
void testIsReadOnly() {
119+
DateTime datetime = Utils.getComponentUnderTest(PATH_DATETIME_CUSTOMIZED, DateTime.class, context);
120+
assertEquals(false, datetime.isReadOnly());
121+
}
122+
123+
@Test
124+
void testIsReadOnlyForCustomized() {
125+
DateTime datetime = Utils.getComponentUnderTest(PATH_DATETIME_CUSTOMIZED, DateTime.class, context);
126+
assertEquals(false, datetime.isReadOnly());
127+
}
128+
129+
@Test
130+
void testMinLength() {
131+
DateTime datetime = Utils.getComponentUnderTest(PATH_DATETIME_CUSTOMIZED, DateTime.class, context);
132+
assertEquals(5, datetime.getMinLength().intValue());
133+
}
134+
135+
@Test
136+
void testMaxLength() {
137+
DateTime datetime = Utils.getComponentUnderTest(PATH_DATETIME_CUSTOMIZED, DateTime.class, context);
138+
assertEquals(10, datetime.getMaxLength().intValue());
139+
}
140+
141+
@Test
142+
void testGetExclusiveMinimum() {
143+
DateTime datetime = Utils.getComponentUnderTest(PATH_NUMBER_DATETIME_EXCLUSIVE, DateTime.class, context);
144+
assertNull(datetime.getMinimum());
145+
assertEquals(8L, datetime.getExclusiveMinimum().longValue());
146+
}
147+
148+
@Test
149+
void testGetExclusiveMaximum() {
150+
DateTime datetime = Utils.getComponentUnderTest(PATH_NUMBER_DATETIME_EXCLUSIVE, DateTime.class, context);
151+
assertNull(datetime.getMaximum());
152+
assertEquals(16L, datetime.getExclusiveMaximum().longValue());
153+
}
154+
155+
@Test
156+
void testGetMinimum() {
157+
DateTime datetime = Utils.getComponentUnderTest(PATH_NUMBER_DATETIME_INPUT, DateTime.class, context);
158+
assertEquals(8, datetime.getMinimum().intValue());
159+
}
160+
161+
@Test
162+
void testGetMaximum() {
163+
DateTime datetime = Utils.getComponentUnderTest(PATH_NUMBER_DATETIME_INPUT, DateTime.class, context);
164+
assertEquals(16, datetime.getMaximum().intValue());
165+
}
166+
167+
@Test
168+
void testGetDisplayFormat() throws Exception {
169+
DateTime datetime = Utils.getComponentUnderTest(PATH_DATETIME_CUSTOMIZED, DateTime.class, context);
170+
assertEquals("datetime", datetime.getFormat());
171+
}
172+
173+
@Test
174+
void testDataLayerProperties() throws IllegalAccessException {
175+
DateTime datetime = Utils.getComponentUnderTest(PATH_DATETIME_DATALAYER, DateTime.class, context);
176+
FieldUtils.writeField(datetime, "dataLayerEnabled", true, true);
177+
FormComponentData dataObject = (FormComponentData) datetime.getData();
178+
assert (dataObject != null);
179+
assert (dataObject.getId()).equals("datetime-1c7bc238a6");
180+
assert (dataObject.getType()).equals("core/fd/components/form/datetime/v1/datetime");
181+
assert (dataObject.getTitle()).equals("Full Name");
182+
assert (dataObject.getFieldType()).equals("datetime");
183+
assert (dataObject.getDescription()).equals("Enter Full Name");
184+
}
185+
}

0 commit comments

Comments
 (0)