This site has been archived. Please visit help.fulcrumapp.com for our new support documentation and contact information.

How do I implement 'Prevent changes after signing' Data Event

Shawn's Avatar

Shawn

20 May, 2016 05:26 AM

I would really like to implement a Data Event for a signature field on one of my forms just like the example 'Prevent changes after signing' (http://developer.fulcrumapp.com/data-events/examples/prevent-changes-after-signed/) but lack the programing knowledge to do it.

Can anyone help me?

Thanks
Shawn

  1. 1 Posted by Bryan McBride on 20 May, 2016 01:24 PM

    Bryan McBride's Avatar

    As long as you have a signature field with a data name of signature, you should be able to just copy that code and paste it into the data events editor.

  2. 2 Posted by Shawn on 16 Jun, 2016 08:59 AM

    Shawn's Avatar

    Thanks for the response Bryan. I only had the Standard Plan and didn't realise that Data Events functionality wasn't available.

    Although I have (a) upgraded to the Pro Plan, (b) a signature field with the data name of 'signature', and (c) copy and pasted the code into the data events editor I still can't get this to work?

    Do I need to change the 'elementsByDataName' or 'dataName' references to be specific to the fields that I want to set as read only?

  3. Support Staff 3 Posted by Alex Helms on 16 Jun, 2016 02:06 PM

    Alex Helms's Avatar

    Hello Shawn,

    You are correct. Anywhere dataname is listed needs to be replaced with the dataname of the field you wish to set as read-only. The elementBy should be kept, but the DataName should be changed in that text.

    Additionally, if you want to lock down more than one field, you will need to create a new for statement for each field by replicating this:

    for (var dataName in this.elementsByDataName) {
          SETREADONLY(dataName, true);
    

    Thanks,
    Alex

  4. 4 Posted by Shawn on 17 Jun, 2016 01:14 AM

    Shawn's Avatar

    Thanks Alex, I followed your instructions but I still can't get this to work. Below is a copy of my code:

    ON('edit-record', function (event) {
      if ($signature) {
        for (var $site_number in this.elementsBy$site_number) {
          SETREADONLY($site_number, true);
        }
      }
    });

    I also tried the following combinations of the 'in this.elementsBy' clause with no success:
    for (var $site_number in this.elementsBy($site_number))
    for (var $site_number in this.elementBy$site_number)
    for (var $site_number in this.elementsBy $site_number)
    for (var $site_number in this.elementsByDataName)

    What am I doing wrong?

  5. Support Staff 5 Posted by Alex Helms on 17 Jun, 2016 02:05 PM

    Alex Helms's Avatar

    Hello Shawn,

    I am sorry, my previous reply was incorrect.

    ON('edit-record', function (event) {
      if ($signature) {
        for (var dataName in this.elementsByDataName) {
          SETREADONLY(dataName, true);
        }
      }
    });
    

    Should set the entire app to read-only as long as the data name for the signature field is called signature. The for() loop goes through each field and then sets the field to read only.

    If you want to set only specific fields to be read-only than you need to remove the for() loop and just use the SETREADONLY() expression for the fields.

    ON('edit-record', function (event) {
      if ($signature) {
          SETREADONLY( 'data_name', true);
      }
    });
    

    The 'data_name' needs to be replaced with data_name of the field that you are using, no $ is needed. So using the field that you mentioned above, the final result should be something like this:

    ON('edit-record', function (event) {
      if ($signature) {
          SETREADONLY( 'site_number', true);
      }
    });
    

    Now, going back to your reply to Bryan, and if your end goal is to have the entire app be read-only if a signature is captured. The original code should work. Can you let me know the name of the app that you have this data event in? I can take a closer look to see why the data event is not working. One thing to note, is the app preview option will probably not work as expected for testing this data event. It would be best to test this on the web or mobile app.

    Sorry for leading you on a slight goose chase.

    Thanks,
    Alex

  6. 6 Posted by Shawn on 29 Jun, 2016 06:21 AM

    Shawn's Avatar

    It worked! Thanks Alex.

    One point to note is that SETREADONLY is only applied after the record is saved.

    Regards
    Shawn

  7. Support Staff 7 Posted by Alex Helms on 29 Jun, 2016 12:28 PM

    Alex Helms's Avatar

    Hello Shawn,

    Great to hear!

    Basically, the event is triggered to run anytime the record is opened in a record editor. So the next time that the record is opened and a signature exist then the fields are set to be read-only.

    Thanks,
    Alex

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac