Skip to content

Lesson 7A. Writing a PreDeleteClient ruleset

Updated jordan.diamante 2024-01-22 / pdexter 2024-02-05

A PreDeleteClient ruleset is called before a client-side document is deleted.

This ruleset operates exclusively on the client side, intervening in the document lifecycle before the actual deletion request is sent to the server.

In this lesson, we script a PreDeleteClient ruleset to confirm a delete action before a client-side document is actually deleted.

Caveat

This ruleset only operates on the client side. Ensure that it does not conflict with server-side deletion functionalities of your Formbird server.

Template Preparation

Because we are creating our own verification prompt, we want to remove the standard prompt that Formbird presents, otherwise we will have two different prompts shown, seemingly doing the same thing.

  • Open your template in a template editor.

  • Add the following line to your template configuration: disableDeleteConfirmationDialog: true

Step 1. Create the PreDeleteClient ruleset

  • Open the Ruleset Editor for a new client-side Ruleset https://your-formbird/form/224bc62858d73ce57a9cb85g

  • Set the name of the RuleSet : Client - PreDeleteClient

  • Group can be set to client, or your organisation name.

  • Save your new ruleset.

The script pane will show the following:

{
#include "JayRule Ruleset Overlay JS",

    ruleset : {
        name : 'Client - PreDeleteClient',

        ruleInitialise : {
            ruleCondition : true,

            ruleAction : function(ntf) {
            }
        }
    }
}
  • Link this ruleset to the Client template, event PreDeleteClient, using the techniques described in previous lessons.

Step 2. Create a Confirmation Dialog

The confirmation dialog in a client-side ruleset can be a simple JavaScript confirm function.

  • Implement the JavaScript confirm in your ruleset as follows:
{
#include "JayRule Ruleset Overlay JS",

    ruleset : {
        name : 'Client - PreDeleteClient',

        ruleConfirmDelete : {
            ruleCondition : true,

            ruleAction : function(ntf) {
                if (!confirm('Are you sure you want to delete this client document?')) {
                    ntf.rulesetFailed = true;
                    // throw new Error('Client-side deletion cancelled by user.');
                }
            }
        }
    }
}

Step 3. Testing

  • Open an existing document with template linked in the Step 1.

  • Click the delete button.

  • There is a default confirm dialog if you click yes, a native dialog (javascript's confirm) from ruleset will appear. If you choose to cancel, ensure the document is not deleted.

If the above is true, you have successfully created a PreDeleteClient ruleset!

Lesson Items covered

  • Creating a PreDeleteClient ruleset for client-side operations.

  • Implementing a client-side confirmation dialog.

  • Testing