AutoSave Function - Javascript

  • 13 October 2017
  • 6 replies
  • 30 views

Userlevel 3
Badge +8

Hi all,

I'm trying to implement an autosave function on one of my forms - http://www.ashu-tosh.com/2017/01/nintex-forms-implementing-auto-save.html

When I try and open my form, it 'hangs'. It's something to do with the way I'm implementing the code.

What am I missing?

My JavaScript button has the css classAutoSaveButton

Yet, do I not need to add something to the beginning of the JavaScript code?  i.e.

Does that mean then I add the following to my button:

Do I need to add another field - timerTex- to my form? and update the client ID javascript variable name?

This post seems to have it nailed, but I don't know what they have done.

Thanks

Andrew


6 replies

Badge +6

Hi Andrew Wilkie‌,

Do you see any errors when you open the developers tool (Press F12 and refresh the page) ?

Can you please share a screenshot of the code that you have added inside the Custom JavaScript (Form settings)

Userlevel 3
Badge +8

Hi Saud Khatri‌,

Code is:

function  AutoSaveButton()
{
  var mins = 3;
//Set the number of minutes you need
var secs = mins * 60;
var currentSeconds = 0;
var currentMinutes = 0;
NWF$(document).ready(function(){
HideAutoSaveControls();
SetAutoFormSaveTimer();
});
function HideAutoSaveControls()
{
if(Is New Mode || Is Edit Mode)
{
NWF$('.AutoSaveButton').css('display','none');
}
}
function SetAutoFormSaveTimer()
{
if(Is New Mode || Is Edit Mode)
{
setTimeout('Decrement()',1000);
}
}
function Decrement()
{
currentMinutes = Math.floor(secs / 60);
currentSeconds = secs % 60;
if(currentSeconds <= 9)
{
currentSeconds = "0" + currentSeconds;
}
secs--;
//Set the element id you need the time put into
//document.getElementById("timerText").innerHTML = currentMinutes + ":" + currentSeconds;
if(secs > -1)
{
setTimeout('Decrement()',1000);
}
else
{
isFormSubmittedAlready=NWF$('.saveButton').is(':disabled');
if(!isFormSubmittedAlready)
{
NWF$('.AutoSaveButton').click();
alert('Form saved automatically as it has not been saved for last '+mins+' minutes');
}
}
}
}

Thanks

Andrew

Badge +2

The original example does not (and should not) be wrapped in an AutoSaveButton() function as you have done. The code needs to run as it is in the form settings, starting with var mins = X. When the Nintex Form is ready, the code runs HideAutoSaveControls() and SetAutoFormSaveTimer(). In X minutes, the button with the AutoSaveButton class is clicked automatically.

Userlevel 3
Badge +8

Hi,

Thanks for the reply.

I only wrapped it because if I don't I just see the following when I try and add/open a new item:

I've tried under both IE and Google Chrome.

I see the above if the button is a "Save" or JavaScript button.

If the button should be a javascript button I assume I've put the correct option in the clientclick field.

Thanks

Andrew

Badge +2

Nothing should be put in the Client Click of the button. By putting the function there in addition to the custom JavaScript for the form, the code would run infinitely, which explains your "Please wait..." message. The code in the example is intended to be put only in the Form Settings custom JavaScript.

Userlevel 3
Badge +8

Hi Jason,

Before I go and knock my head against the coffee machine.

All now working.

Blindly I copied the code from the webpage.

There are the following lines: if(Is New Mode || Is Edit Mode).

These I needed to actually replace with the Insert Reference>New Mode/Edit Mode option, not just plain text - doh.

Remember to add the AutoSaveButton to the css class of the button.

The message pops up:

Job Done.

Reply