Skip to content

Custom Function is not getting registered. #1877

Description

@ChristoVP

Expected Behaviour

we created a custom function, that is being shown during authoring, but during runtime its not able to find it.

Actual Behaviour

Function to execute

Reproduce Scenario (including but not limited to)

Steps to Reproduce

/**

  • @name validateDateOfBirth

  • @PARAM {object} field

  • @PARAM {number} upperAgeLimit - Enter the upper age limit value

  • @returns {boolean} - True if valid, false otherwise
    */
    function validateDateOfBirth(field, upperAgeLimit) {
    const inputVal = field.$value;
    if (!inputVal || (inputVal && Date.parse(inputVal) && new Date().setHours(0, 0, 0, 0) >= Date.parse(inputVal))) {
    const today = new Date();
    const inputDate = new Date(inputVal);

      const inputDateArray = inputVal.split('/');
      inputDate.setFullYear(parseInt(inputDateArray[inputDateArray.length - 1], 10));
    
      const currentYear = today.getFullYear();
      const inputYear = inputDate.getFullYear();
    
      let leapYearCount = 0;
      for (let i = inputYear; i <= currentYear; i++) {
          if ((i % 4 === 0 && i % 100 !== 0) || i % 400 === 0) {
              leapYearCount++;
          }
      }
      const ageInDays = Math.floor(Math.floor(Math.floor(Math.floor((+today - +inputDate) / 1000) / 60) / 60) / 24);
      const ageInYears = ((ageInDays - (366 * leapYearCount)) / 365) + leapYearCount;
      return ageLimitCheck(ageInYears, upperAgeLimit);
    

    } else {
    return false;
    }
    }
    /**

  • @Private
    */
    function ageLimitCheck(ageInYears, upperAgeLimit) {
    if (ageInYears >= 18) {
    if (upperAgeLimit) {
    return ageInYears < upperAgeLimit + 1 ? true : false;
    } else {
    return true;
    }
    } else {
    return false;
    }
    }

Image

Platform and Version

AEM Version (mention the exact version in case of cloud SDK)

AEM 6.5.1 LTS

AEM Forms Version

1.1.74

Sample Code that illustrates the problem

Logs taken while reproducing problem

Image

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions