1
0
-1
I regularly need to calculate someone's age based on their date of birth and the current date. Is there a library with common functions like that that I can use for my field validations and calculations?
  1. Jye Cusch
    Hi Jeroen,

    There are no JS Libraries built into Composer by default that would allow you to perform the age calculation you mentioned, but there are a few ways you could go about adding that sort of functionality.

    Custom Widget


    If the validation is always being performed in a particular type of field, such as a date/date-of-birth field you could write the validation once in the validation script of the field and then save the field as a custom widget. To save it as a custom widget right-click on the field in the 'Structure' pane and select 'Save As Custom Widget...'.

    Custom Library


    Alternatively, you can add additional JavaScript libraries to a form, for steps on how to do that please refer to our existing page on Importing a JavaScript Library
  2. Howard Treisman
    Actually there is a library for doing this, called moment.js (an open source library) and some convenience functions for commonly used calculations.
    https://composer.dev.avoka.com/composer/doc/index.html?working_with_dates.htm
    Take a look at the End date field in the Date range block for an example of how to use this.
  3. Matthew White
    As of writing this comment, the current version of moment.js is 2.8.3 and the version in TM is 1.7.0. We intended to use the moment.js add() function to calculate a date 28 days in the future but have run into a breaking api change. Version 1.7 expects date.add('days', 28) while version 2.8.3 expects date.add(28, 'days'). Version 2.0 supported both versions. Are there intentions to update the moment.js library and if so, how will the TM product deal with api changes which will break existing code?
    In searching for this page which I remembered seeing previously, I entered "moment" without the quotes into the "Knowledge Base/Community Q & A/Composer" Search Box. It returned no results. It appears to only look at the page titles. A much better experience would be allowing users to search Knowledge Base article content.
    Matt
CommentAdd your comment...

1 answer

  1.  
    1
    0
    -1
    1. Howard Treisman
      Oops, better URL:https://composer.demo.avoka.com/composer/doc/index.html?working_with_dates.htm
    CommentAdd your comment...