Skip to content

Relationship between Rulesets & Templates

NB: The following applies to Formbird versions post 1.1.197.

Ruleset-Template-ER

A template holds several event ruleset links, defined as the following root level properties:

Property Event
onLoadClientRuleRel OnLoad
onFieldChangeClientRuleRel OnFieldChange
preSaveClientRuleRel PreSave
preSaveServerRuleRel PreSaveServer
postSaveServerRuleRel PostSave

Note that more than one ruleset can be linked to any event on a template.

Example Template

{
    "name": "Insect",
    "appTags": [
        "dexwise",
        "entomology",
        "insect"
    ],
    "summaryNameRule": "Insect - {{commonName}} ({{genus}} {{species}})",
    "summaryDescriptionRule": "{{description}}",
    "formColor": "#E3E3E3",
    "systemHeader": {...},
    "documentId": "07e7fbd0-cee3-11e5-aa08-fdabe14f1759",
    "components": [...],
    "onLoadClientRuleRel": [
        {
            "documentId": "78268870-8c12-11e6-8927-755e7e62df8c",
            "name": "Insect - OnLoad (JS)"
        },
        {
            "documentId": "007ba540-c833-11e7-af55-9b20b8681e48",
            "name": "Insect - OnFieldState"
        }
    ],
    "onFieldChangeClientRuleRel": [
        {
            "documentId": "569708a56f63cbc353af47fd",
            "name": "Insect - OnFieldChange"
        },
        {
            "documentId": "007ba540-c833-11e7-af55-9b20b8681e48",
            "name": "Insect - OnFieldState"
        }
    ],
    "preSaveClientRuleRel": [
        {
            "documentId": "6b139450-4952-11e6-ae2d-a99c41a4e267",
            "name": "Insect - PreSave"
        }
    ],
    "preSaveServerRuleRel": [
        {
            "documentId": "563388f0-4953-11e6-ae2d-a99c41a4e267",
            "name": "Insect - PreSaveServer"
        }
    ],
    "postSaveServerRuleRel": [
        {
            "documentId": "56524b945bec6a9d0a93bcc3",
            "name": "Insect - PostSave"
        }
    ]
}

Applying Rulesets to Templates

While it is possible to apply a Ruleset to a Template by directly editing the Template, there is available a special overlay template called "Ruleset Linker" which can be used instead.

The overlay template's document ID should be abb10be0-b9dc-11e7-8013-1f0b88022708, and placing this after a template's url with slash (/) will display the template's ruleset links as below.

Eg: https://comp-dev.formbird.com/#/form/07e7fbd0-cee3-11e5-aa08-fdabe14f1759/abb10be0-b9dc-11e7-8013-1f0b88022708

There is a link at the bottom of the overlay template which can be dragged to your bookmark bar for a quick way to view any template with this overlay.

RulesetLinkerOverlayScreen

You may notice in the above examples that OnLoad and OnFieldChange both call a common ruleset, called "XXXX - OnFieldState".

There is no actual event called "FieldState". It is what we might call a "pseudo event", which we can emulate by attaching an "OnFieldState" ruleset to events where it should occur.

An OnFieldState ruleset is a good place to script the setting of field states such as enablement and mandatoriness; this generally needs to be performed for all fields both on loading (OnLoad), plus for particular fields on a specific field changing (OnFieldChange).

For example, if a checkbox "Requires Verification" is checked, we want to enable and mandate the fields "Verification Detail" and "Verified By".

This needs to occur on the changing of the checkbox field, either to checked or unchecked. So, it needs to occur in response to the event "OnFieldChange".

It also needs to occur when we come back the next day and open this document again. Formbird documents do not remember their enabled/mandatory states from the previous browser session, so the states need to be applied again. So, it also needs to occur in response to the event "OnLoad".