diff --git a/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/internal/form/ReservedProperties.java b/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/internal/form/ReservedProperties.java index b95917e3f3..9cc711f3e3 100644 --- a/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/internal/form/ReservedProperties.java +++ b/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/internal/form/ReservedProperties.java @@ -87,6 +87,8 @@ private ReservedProperties() { public static final String PN_MINIMUM = "minimum"; public static final String PN_EXCLUSIVE_MINIMUM = "exclusiveMinimum"; public static final String PN_EXCLUSIVE_MAXIMUM = "exclusiveMaximum"; + public static final String PN_EXCLUDE_MINIMUM = "excludeMinimum"; + public static final String PN_EXCLUDE_MAXIMUM = "excludeMaximum"; public static final String PN_EXCLUDE_MINIMUM_CHECK = "excludeMinimumCheck"; public static final String PN_EXCLUDE_MAXIMUM_CHECK = "excludeMaximumCheck"; public static final String PN_ENFORCE_ENUM = "enforceEnum"; diff --git a/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/internal/models/v1/form/DatePickerImpl.java b/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/internal/models/v1/form/DatePickerImpl.java index b97416f5b8..8dfa4d4bd1 100644 --- a/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/internal/models/v1/form/DatePickerImpl.java +++ b/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/internal/models/v1/form/DatePickerImpl.java @@ -22,14 +22,18 @@ import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.resource.Resource; +import org.apache.sling.models.annotations.Default; import org.apache.sling.models.annotations.Exporter; import org.apache.sling.models.annotations.Model; +import org.apache.sling.models.annotations.injectorspecific.InjectionStrategy; import org.apache.sling.models.annotations.injectorspecific.SlingObject; +import org.apache.sling.models.annotations.injectorspecific.ValueMapValue; import org.jetbrains.annotations.NotNull; import com.adobe.cq.export.json.ComponentExporter; import com.adobe.cq.export.json.ExporterConstants; import com.adobe.cq.forms.core.components.internal.form.FormConstants; +import com.adobe.cq.forms.core.components.internal.form.ReservedProperties; import com.adobe.cq.forms.core.components.models.form.ConstraintType; import com.adobe.cq.forms.core.components.models.form.DatePicker; import com.adobe.cq.forms.core.components.util.AbstractFieldImpl; @@ -46,6 +50,16 @@ public class DatePickerImpl extends AbstractFieldImpl implements DatePicker { @SlingObject private Resource resource; + /*** Not to be changed, kept for backward compatibility **/ + @ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = ReservedProperties.PN_EXCLUDE_MINIMUM) + @Default(booleanValues = false) + protected boolean excludeMinimum; + + @ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = ReservedProperties.PN_EXCLUDE_MAXIMUM) + @Default(booleanValues = false) + protected boolean excludeMaximum; + /*** end of Not to be changed **/ + private Date exclusiveMinimumVaue; private Date exclusiveMaximumValue; @@ -84,8 +98,8 @@ public Date getExclusiveMinimumDate() { @PostConstruct private void initDatePicker() { - exclusiveMaximumValue = ComponentUtils.getExclusiveValue(exclusiveMaximum, maximumDate, null); - exclusiveMinimumVaue = ComponentUtils.getExclusiveValue(exclusiveMinimum, minimumDate, null); + exclusiveMaximumValue = ComponentUtils.getExclusiveValue(exclusiveMaximum, maximumDate, excludeMaximum); + exclusiveMinimumVaue = ComponentUtils.getExclusiveValue(exclusiveMinimum, minimumDate, excludeMinimum); // in json either, exclusiveMaximum or maximum should be present if (exclusiveMaximumValue != null) { maximumDate = null; diff --git a/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/util/ComponentUtils.java b/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/util/ComponentUtils.java index 9a7f3c40fd..a1c69a051f 100644 --- a/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/util/ComponentUtils.java +++ b/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/util/ComponentUtils.java @@ -167,6 +167,9 @@ public static T getExclusiveValue(Object exclusiveValue, T value, Object exc } else { return null; } + } else if (Boolean.TRUE.equals(exclusiveValueCheck) && value != null) { // backward compatibility case // not to be changed + // If so, return the value + return (T) value; } else { // Handle other cases or return null if desired return null; diff --git a/bundles/af-core/src/test/java/com/adobe/cq/forms/core/components/internal/models/v1/form/DatePickerImplTest.java b/bundles/af-core/src/test/java/com/adobe/cq/forms/core/components/internal/models/v1/form/DatePickerImplTest.java index dabcbb1e4b..d7ff283a62 100644 --- a/bundles/af-core/src/test/java/com/adobe/cq/forms/core/components/internal/models/v1/form/DatePickerImplTest.java +++ b/bundles/af-core/src/test/java/com/adobe/cq/forms/core/components/internal/models/v1/form/DatePickerImplTest.java @@ -47,6 +47,7 @@ public class DatePickerImplTest { private static final String PATH_DATEPICKER = CONTENT_ROOT + "/datepicker"; private static final String PATH_DATEPICKER_DATALAYER = CONTENT_ROOT + "/datepicker-datalayer"; private static final String PATH_DATEPICKER_DISPLAY_VALUE_EXPRESSION = CONTENT_ROOT + "/datepicker-displayValueExpression"; + private static final String PATH_DATEPICKER_BACKWARD_COMPATIBLE = CONTENT_ROOT + "/datepicker-backwardcompatible"; private final AemContext context = FormsCoreComponentTestContext.newAemContext(); @@ -241,6 +242,12 @@ void testJSONExport() throws Exception { Utils.testJSONExport(datePicker, Utils.getTestExporterJSONPath(BASE, PATH_DATEPICKER)); } + @Test + void testJSONExportBackwardCompatibility() throws Exception { + DatePicker datePicker = Utils.getComponentUnderTest(PATH_DATEPICKER_BACKWARD_COMPATIBLE, DatePicker.class, context); + Utils.testJSONExport(datePicker, Utils.getTestExporterJSONPath(BASE, PATH_DATEPICKER_BACKWARD_COMPATIBLE)); + } + @Test void testJSONExportForCustomized() throws Exception { DatePicker datePicker = Utils.getComponentUnderTest(PATH_DATEPICKER_CUSTOMIZED, DatePicker.class, context); diff --git a/bundles/af-core/src/test/java/com/adobe/cq/forms/core/components/internal/models/v1/form/NumberInputImplTest.java b/bundles/af-core/src/test/java/com/adobe/cq/forms/core/components/internal/models/v1/form/NumberInputImplTest.java index 2f6a56d0b7..a69b567eaf 100644 --- a/bundles/af-core/src/test/java/com/adobe/cq/forms/core/components/internal/models/v1/form/NumberInputImplTest.java +++ b/bundles/af-core/src/test/java/com/adobe/cq/forms/core/components/internal/models/v1/form/NumberInputImplTest.java @@ -51,6 +51,7 @@ public class NumberInputImplTest { private static final String PATH_NUMBER_INPUT_INTEGER_TYPE = CONTENT_ROOT + "/numberinput-integer-type"; private static final String PATH_NUMBER_INPUT_CONSTRAINTS = CONTENT_ROOT + "/numberinput-exclusive"; private static final String PATH_NUMBER_INPUT_BACKWARD_COMPATIBLE = CONTENT_ROOT + "/numberinput-backwardcompatible"; + private static final String PATH_NUMBER_INPUT_BACKWARD_COMPATIBLE_2 = CONTENT_ROOT + "/numberinput-backwardcompatible-2"; private static final String PATH_NUMBER_INPUT_BACKWARD_COMPATIBLE_STRING = CONTENT_ROOT + "/numberinput-backwardcompatible-string"; private static final String PATH_NUMBER_INPUT = CONTENT_ROOT + "/numberinput"; private static final String PATH_NUMBER_INPUT_DATALAYER = CONTENT_ROOT + "/numberinput-datalayer"; @@ -267,6 +268,12 @@ void testJSONExportBackwardCompatible() throws Exception { Utils.testJSONExport(numberInput, Utils.getTestExporterJSONPath(BASE, PATH_NUMBER_INPUT_BACKWARD_COMPATIBLE)); } + @Test + void testJSONExportBackwardCompatible2() throws Exception { + NumberInput numberInput = Utils.getComponentUnderTest(PATH_NUMBER_INPUT_BACKWARD_COMPATIBLE_2, NumberInput.class, context); + Utils.testJSONExport(numberInput, Utils.getTestExporterJSONPath(BASE, PATH_NUMBER_INPUT_BACKWARD_COMPATIBLE_2)); + } + @Test void testGetProperties() throws Exception { NumberInput numberInput = Utils.getComponentUnderTest(PATH_NUMBER_INPUT_CUSTOMIZED, NumberInput.class, context); diff --git a/bundles/af-core/src/test/resources/form/datepicker/exporter-datepicker-backwardcompatible.json b/bundles/af-core/src/test/resources/form/datepicker/exporter-datepicker-backwardcompatible.json new file mode 100644 index 0000000000..1c51515690 --- /dev/null +++ b/bundles/af-core/src/test/resources/form/datepicker/exporter-datepicker-backwardcompatible.json @@ -0,0 +1,25 @@ +{ + "id": "datepicker-0ac1fed1fe", + "fieldType": "date-input", + "name": "DoB", + "description": "Date of Birth", + "type": "string", + "label": { + "value": "DoB" + }, + "events": { + "custom:setProperty": [ + "$event.payload" + ] + }, + "properties": { + "fd:dor": { + "dorExclusion": false + }, + "fd:path": "/content/datepicker-backwardcompatible" + }, + "format": "date", + "exclusiveMaximum": "2024-07-23", + "exclusiveMinimum": "2024-07-10", + ":type": "core/fd/components/form/datepicker/v1/datepicker" +} \ No newline at end of file diff --git a/bundles/af-core/src/test/resources/form/datepicker/test-content.json b/bundles/af-core/src/test/resources/form/datepicker/test-content.json index 649610aa94..67aef568ce 100644 --- a/bundles/af-core/src/test/resources/form/datepicker/test-content.json +++ b/bundles/af-core/src/test/resources/form/datepicker/test-content.json @@ -89,6 +89,33 @@ "fd:path": "/content/forms/af/af2/jcr:content/guideContainer/datepicker" } }, + "datepicker-backwardcompatible": { + "id": "datepicker-0ac1fed1fe", + "sling:resourceType": "core/fd/components/form/datepicker/v1/datepicker", + "fieldType": "date-input", + "excludeMaximum" : true, + "excludeMinimum" : true, + "minimumDate": "Wed Jul 10 2024 00:00:00 GMT+0000", + "maximumDate": "Tue Jul 23 2024 00:00:00 GMT+0000", + "description": "Date of Birth", + "jcr:title" : "DoB", + "name": "DoB", + "type": "string", + "label": { + "value": "DoB" + }, + "events": { + "custom:setProperty": [ + "$event.payload" + ] + }, + "properties": { + "fd:dor": { + "dorExclusion": false + }, + "fd:path": "/content/forms/af/af2/jcr:content/guideContainer/datepicker" + } + }, "datepicker-displayValueExpression" : { "jcr:primaryType": "nt:unstructured", "sling:resourceType" : "core/fd/components/form/datepicker/v1/datepicker", diff --git a/bundles/af-core/src/test/resources/form/numberinput/exporter-numberinput-backwardcompatible-2.json b/bundles/af-core/src/test/resources/form/numberinput/exporter-numberinput-backwardcompatible-2.json new file mode 100644 index 0000000000..d605eb9bf0 --- /dev/null +++ b/bundles/af-core/src/test/resources/form/numberinput/exporter-numberinput-backwardcompatible-2.json @@ -0,0 +1,24 @@ +{ + ":type": "core/fd/components/form/numberinput/v1/numberinput", + "description": "Enter your phone number.", + "events": { + "custom:setProperty": [ + "$event.payload" + ] + }, + "exclusiveMaximum": 2000002, + "exclusiveMinimum": 10002, + "fieldType": "number-input", + "id": "numberinput-57e5de6073", + "label": { + "value": "Phone Number" + }, + "name": "Phone Number", + "properties": { + "fd:dor": { + "dorExclusion": false + }, + "fd:path": "/content/numberinput-backwardcompatible-2" + }, + "type": "number" +} diff --git a/bundles/af-core/src/test/resources/form/numberinput/test-content.json b/bundles/af-core/src/test/resources/form/numberinput/test-content.json index b4804526d2..3211baa765 100644 --- a/bundles/af-core/src/test/resources/form/numberinput/test-content.json +++ b/bundles/af-core/src/test/resources/form/numberinput/test-content.json @@ -133,6 +133,33 @@ "fd:path": "/content/forms/af/af2/jcr:content/guideContainer/accordion/item_2/numberinput" } }, + "numberinput-backwardcompatible-2": { + "id": "numberinput-57e5de6073", + "sling:resourceType": "core/fd/components/form/numberinput/v1/numberinput", + "fieldType": "number-input", + "description": "Enter your phone number.", + "name": "Phone Number", + "jcr:title" : "Phone Number", + "type": "string", + "label": { + "value": "Phone Number" + }, + "events": { + "custom:setProperty": [ + "$event.payload" + ] + }, + "excludeMinimumCheck" : true, + "excludeMaximumCheck" : true, + "minimum" : 10002, + "maximum" : 2000002, + "properties": { + "fd:dor": { + "dorExclusion": false + }, + "fd:path": "/content/forms/af/af2/jcr:content/guideContainer/accordion/item_2/numberinput" + } + }, "numberinput-backwardcompatible-string": { "sling:resourceType": "core/fd/components/form/numberinput/v1/numberinput", "fieldType": "number-input", diff --git a/it/content/src/main/content/jcr_root/content/forms/af/core-components-it/samples/datepicker/basic/.content.xml b/it/content/src/main/content/jcr_root/content/forms/af/core-components-it/samples/datepicker/basic/.content.xml index 9759c11c97..40ef5f82a5 100755 --- a/it/content/src/main/content/jcr_root/content/forms/af/core-components-it/samples/datepicker/basic/.content.xml +++ b/it/content/src/main/content/jcr_root/content/forms/af/core-components-it/samples/datepicker/basic/.content.xml @@ -187,6 +187,23 @@ textIsRich="[true,true,true]" unboundFormElement="{Boolean}false" visible="{Boolean}true"/> + diff --git a/it/content/src/main/content/jcr_root/content/forms/af/core-components-it/samples/numberinput/basic/.content.xml b/it/content/src/main/content/jcr_root/content/forms/af/core-components-it/samples/numberinput/basic/.content.xml index 84b51cab1b..a21ad13cfa 100755 --- a/it/content/src/main/content/jcr_root/content/forms/af/core-components-it/samples/numberinput/basic/.content.xml +++ b/it/content/src/main/content/jcr_root/content/forms/af/core-components-it/samples/numberinput/basic/.content.xml @@ -139,12 +139,27 @@ displayValueExpression="formatCreditCardNumber($field)" fieldType="number-input" name="numberinput1710483567726"> - - + + + diff --git a/ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/datepicker/v1/datepicker/_cq_dialog/.content.xml b/ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/datepicker/v1/datepicker/_cq_dialog/.content.xml index 91372443fb..4886b1c14d 100644 --- a/ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/datepicker/v1/datepicker/_cq_dialog/.content.xml +++ b/ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/datepicker/v1/datepicker/_cq_dialog/.content.xml @@ -95,7 +95,7 @@ + + { it("test for aemembedcontainer presence inside iframe", () => { getIframeBody().find('.cmp-adaptiveform-container').should('have.length', 1); - getIframeBody().find('.cmp-adaptiveform-container').find('.cmp-adaptiveform-numberinput__widget').should('have.length', 8); + getIframeBody().find('.cmp-adaptiveform-container').find('.cmp-adaptiveform-numberinput__widget').its('length').should('be.gt', 8); }) it("test for form presence in nonIframe mode", () => { diff --git a/ui.tests/test-module/specs/datepicker/datepicker.runtime.spec.js b/ui.tests/test-module/specs/datepicker/datepicker.runtime.spec.js index a109ddba94..8a16fbe67c 100644 --- a/ui.tests/test-module/specs/datepicker/datepicker.runtime.spec.js +++ b/ui.tests/test-module/specs/datepicker/datepicker.runtime.spec.js @@ -340,4 +340,19 @@ describe("Form Runtime with Date Picker", () => { cy.get(".dp-caption").should('include.text', todayYear); }); }); + + it("check minimum, maximum, exclusiveMinimum and exclusiveMaximum constraints ", () => { + const [dateInput10, dateInput10FieldView] = Object.entries(formContainer._fields)[10]; + const input = "2024-07-10"; + let model = dateInput10FieldView.getModel(); + cy.get(`#${dateInput10}`).find("input").clear().type(input).blur().then(x => { + cy.get(`#${dateInput10}`).find(".cmp-adaptiveform-datepicker__errormessage").should('have.text',"Value must be greater than 2024-07-10."); + cy.get(`#${dateInput10}`).find("input").clear().type("2024-07-12").blur().then(x => { + cy.get(`#${dateInput10}`).find(".cmp-adaptiveform-datepicker__errormessage").should('have.text',""); + cy.get(`#${dateInput10}`).find("input").clear().type("2024-07-26").blur().then(x => { + cy.get(`#${dateInput10}`).find(".cmp-adaptiveform-datepicker__errormessage").should('have.text',"Value must be less than 2024-07-23."); + }) + }) + }) + }); }) diff --git a/ui.tests/test-module/specs/numberinput/numberinput.runtime.spec.js b/ui.tests/test-module/specs/numberinput/numberinput.runtime.spec.js index 41cbb05462..1f1f1fcf23 100644 --- a/ui.tests/test-module/specs/numberinput/numberinput.runtime.spec.js +++ b/ui.tests/test-module/specs/numberinput/numberinput.runtime.spec.js @@ -249,6 +249,18 @@ describe("Form with Number Input", () => { }) } }); + + it("check minimum, maximum, exclusiveMinimum and exclusiveMaximum constraints ", () => { + const [numberInput9, numberInput9FieldView] = Object.entries(formContainer._fields)[8]; + const input = "1212"; + let model = numberInput9FieldView.getModel(); + cy.get(`#${numberInput9}`).find("input").clear().type(input).blur().then(x => { + cy.get(`#${numberInput9}`).find(".cmp-adaptiveform-numberinput__errormessage").should('have.text',"Value must be less than or equal to 100."); + cy.get(`#${numberInput9}`).find("input").clear().type("10").blur().then(x => { + cy.get(`#${numberInput9}`).find(".cmp-adaptiveform-numberinput__errormessage").should('have.text',"Minimum value should be 10"); + }) + }) + }); }) describe("Form with Number Input Required Validation", () => {