Search code examples
formsaem

Restrict future date selection in adaptive forms AEM


**enter image description here**

I want to restrict future date selection in AEM adaptive forms. Also if there is any way to restrict date selection unto any particular date (any future or past date)


Solution

  • You can configure the Minimum Value and the Maximum Value for the date field to prevent the user from selecting a date which is outside this range. However, there are certain restrictions

    1. The values mentioned above cannot be dynamic and would be a fixed value. Hence, you cannot set them to something like today or now. It has to be a value in the ISO format which is yyyy-mm-dd.
    2. As long as you have not specified a display pattern (i.e., you are using the default value of the field), it would bring up the browser's native date picker which disables the dates outside your minimum and maximum range. However, if you set a display format, then AEM's datepicker would be displayed and it doesn't disabled dates outside the min-max specified.

    That being said, you can still write a validation rule which throws an error if the value selected/entered is outside the valid date range or if it is greater than today (depending on what you want to validate).

    1. Open the rule editor.
    2. Click on Create rule.
    3. Select Validate by clicking on the dropdown arrow beside the When (which is the default)
    4. In the Using Expression section, select your date field for the First Object, select is before for the operator and select Function Output > Get Current Date for the second object.

    The final rule should look as shown below

    enter image description here