Computable field for age

salam,

I am looking for an extension that calculates age based on birth date selection

thanks in advance

Hello @Alilo_Dris

Try this extension GitHub - rezo-labs/directus-extension-computed-interface: Perform computed value based on other fields

Hello @Alilo_Dris,

Please install this extension into your Directus instance:
:link: https://www.npmjs.com/package/directus-extension-computed-interface


How to Use

  1. Go to Settings, and create a new field with type string or number.
  2. In the Interface panel, choose Computed interface. There are 8 configurable options:

Interface Options

  • Template
    Similar to M2M interface, determines how the field is calculated. Learn more about syntax in the next section.

  • Field Mode – Choose how the value is displayed:

    • null: (Default) Shows input with the computed value, but allows manual editing.
    • Display Only: Shows computed value but does not save it to the database. Good for alias fields.
    • Read Only: Shows input with the computed value and disallows manual editing.
  • Prefix
    A string to prefix the computed value.

  • Suffix
    A string to suffix the computed value.

  • Custom CSS
    JSON object for inline style binding (only works with Display Only and Read Only).
    Customize appearance like font size, color, etc.
    Example:

    { "color": "red", "font-size": "20px" }
    
  • Debug Mode
    Helps debug your template. Shows error messages if the template is invalid and logs the output of each part.

  • Compute If Empty
    Computes the value only if the field is empty. Useful for generating a created date, unique ID, etc.

  • Initial Compute
    Computes the value when opening the form. Useful for dynamic values like current date.


Example

{{SUBTRACT(YEAR($NOW), YEAR(DATE(date_created)))}}

This will compute the difference in years between the current date and the date_created field.


Hi Ahmad,

I created a flow to check for duplicates when updating a record.
However, in the “Read Data” node, only the key (id) is being retrieved, and the other fields from $trigger.payload are coming through as NaN or undefined.

Here is the filter used in the Read Data node:

{
    "filter": {
        "_and": [
            {
                "id_cours": {
                    "_neq": "{{ $trigger.keys[0] }}"
                }
            },
            {
                "Ense": {
                    "_eq": "{{ $trigger.payload.Ense }}"
                }
            },
            {
                "activite": {
                    "_eq": "{{ $trigger.payload.activite }}"
                }
            },
            {
                "date_cours": {
                    "_eq": "{{ $trigger.payload.date_cours }}"
                }
            }
        ]
    }
}

And here is the resulting SQL error:

ER_BAD_FIELD_ERROR: Unknown column 'NaN' in 'where clause'
select `cours`.`id_cours`, ... 
where (
    not `id_cours` = 111 
    and `Ense` = NaN 
    and `activite` = NaN 
    and `date_cours` = 'undefined'
)

As you can see, the key (id_cours = 111) is correct, but the other fields from the trigger payload (Ense, activite, date_cours) are not being retrieved during the update event.

Do you know why $trigger.payload is empty during the update, and how I can correctly access the updated fields inside the flow?

Thanks in advance!