TreeINFO-For-M365 documentation
    Preparing search index...

    List of examples for FunctionValidation


    This simple validation example validates that field value includes a balloon 🎈

    Form configuration example:

    {
    "Groups": [
    {
    "Name": "Group 1",
    "Fields": [
    {
    "InternalName": "my_field",
    "Validation": {
    "ValidationFunction": "validateMyField"
    }
    }
    ]
    }
    ],
    "Resources": [
    {
    "LCID": "1029",
    "validations": {
    "shouldIncludeABalloon": "Pole by mělo obsahovat balónek 🎈"
    }
    },
    {
    "LCID": "1033",
    "validations": {
    "shouldIncludeABalloon": "Field should include a baloon 🎈"
    }
    }
    ]
    }

    Custom script example:

    function validateMyField(value) {
    const { translation } = tisa.utils;

    if (!value.includes("🎈")) {
    return translation("validations.shouldIncludeABalloon");
    }
    }

    This validation validates that the field's date is within the range of ±7 days from today.

    Form configuration example:

    {
    "Groups": [
    {
    "Name": "Group 1",
    "Fields": [
    {
    "InternalName": "my_field",
    "Validation": {
    "ValidationFunction": "validateDateRage"
    }
    }
    ]
    }
    ],
    "Resources": [
    {
    "LCID": "1029",
    "validations": {
    "dateNotWithinRange": "Datum by mělo být v rozmezí ±7 dní."
    }
    },
    {
    "LCID": "1033",
    "validations": {
    "dateNotWithinRange": "Date should be within the range of ±7 days."
    }
    }
    ]
    }

    Custom script example:

    function validateDateRage(value) {
    const { translation } = tisa;

    const date = new Date(value);
    const today = new Date();
    const diffDays = (date - today) / (1000 * 60 * 60 * 24);

    if (Math.abs(diffDays) >= 7) {
    return translation("validations.dateNotWithinRange");
    }
    }