You are viewing limited content. For full access, please sign in.

Question

Question

New Forms JavaScript

asked on April 15

Good day all

 

We use the following code on classic designer to send a pop up message to the user telling them they need to save data before leaving the form.

Please can I ask for assistance for this to work on the new modern forms designer

Thank you

 

$(document).ready(function() {

// Check if browser is closed without submitting, then raise alert

 

canLeaveForm = false;

 

$('.form-q').change(function(){

    canLeaveForm = false;

  });

 

  window.onbeforeunload = function()

  {

    if (!canLeaveForm)

    { return 'Are you sure you want to leave this page without saving changes?'; }

    else

    { return; }

  }

 

  $('.Submit').on('click', function() {

    var noErrors = true;

    $('#form1').parsley().validate();

    $('.parsley-error').each(function() {

      noErrors = false;

    });

    if (noErrors) { canLeaveForm = true; }

  });

  });

0 0

Replies

replied on April 15

Hi August, I'm not sure if this will work but try this:  

// Check if browser is closed without submitting, then raise alert

var canLeaveForm = false;

 

// Change event for form fields

LFForm.subscribe('change', function(event) {

    if (event.fieldId === 'yourFieldId') {

        canLeaveForm = false;

    }

});

 

// Before unload event

window.onbeforeunload = function() {

    if (!canLeaveForm) {

        return 'Are you sure you want to leave this page without saving changes?';

    }

};

 

// Submit button click event

LFForm.subscribe('click', function(event) {

    if (event.fieldId === 'submitButtonId') {

        var noErrors = true;

        LFForm.validateForm();

        $('.parsley-error').each(function() {

            noErrors = false;

        });

        if (noErrors) {

            canLeaveForm = true;

        }

    }

});

 

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.