Page 1 of 1

Double recording of data

Posted: Tue Jan 07, 2020 3:38 pm
by mariri
Hi !

Sometimes data subform are recorded twice when the user just click on the Save button. How is this possible? :shock:

Thanks for ur help !

Re: Double recording of data

Posted: Tue Jan 07, 2020 4:05 pm
by kev1n
Hi,

Is it possible that the duplicate entries are generated by clicking "Save" 2 times in a row? Is this reproducible for you?

Re: Double recording of data

Posted: Tue Jan 07, 2020 4:21 pm
by mariri
Ok I tried to record data by clincking several times on the Save button and data was duplicated... :cry:

Re: Double recording of data

Posted: Tue Jan 07, 2020 6:02 pm
by kev1n
Add the following Javascript under Setup -> Header. This should prevent a user from double-clicking the save button (of any form)

Code: Select all

function nuOnLoad() {
  
   // Disable the save button for 1.5 seconds to prevent a user from double-clicking it.
    $('#nuSaveButton').click(function() {
        nuDisable('nuSaveButton');
        setTimeout(
            function() {
                nuEnable('nuSaveButton');
            }, 1500);
    });
  
}

Re: Double recording of data

Posted: Tue Jan 07, 2020 10:46 pm
by Janusz
Additionally to above code it should be probably added the nuSaveAction() function in the onclick.
In my case I am protecting from double click as well Add button and Print button to avoid some issues I had before with them.
And probably Clone button should be added if someone is using it.
Please find enclosed the code I use in my applications (placed in Header section)

Code: Select all

function nuOnLoad() {
// .. other code if exists

// disable double click for Save, Add and  Print buttons
        if(nuFormType() == 'edit') {
        $('#nuSaveButton').attr('onclick','field=this.id; nuDisable(field); nuSaveAction(); setTimeout(function(){nuEnable(field);},2000);');
            }
if(nuFormType() == 'browse') {
$('#nuAddButton').attr('onclick','nuDisable(this.id); nuAddAction();');
$('#nuPrintButton').attr('onclick','field=this.id; nuDisable(field); nuPrintAction(); setTimeout(function(){nuEnable(field);},2000);');
    }
}

Re: Double recording of data

Posted: Wed Jan 08, 2020 9:25 am
by kev1n
@Janusz: .attr('onclick') will override an existing event handler, while .click(...) will just add an additional handler. That's the reason you don't need to call nuSaveAction(); etc. using my code.

Here is a modified and more generic code, that will work for any Action Button (Save, Delete, Print, Clone etc.)

Please let me know if it works for you.

Code: Select all

// After clicking a nuActionButton (Save, Delete, Print, Clone etc.), disable it for 1.5 secs to prevent a user from double-clicking it.
function preventButtonDblClick() {

	$('.nuActionButton').click(function() {	
		var id = $(this).attr("id");	
		nuDisable(id);
		setTimeout(
			function() {
				nuEnable(id);
			}, 1500);
	});
}

function nuOnLoad() {

   preventButtonDblClick();

}

Re: Double recording of data

Posted: Wed Jan 08, 2020 9:52 am
by Janusz
Kev1n, thanks for this explanation - I was considering onclick and click as equivalent - but looks like there are some diiferences.
Just tested your script - and it's working OK - thanks.

Re: Double recording of data

Posted: Wed Jan 08, 2020 1:42 pm
by mariri
Thanks for ur replies ! It works for me

Re: Double recording of data

Posted: Fri Jul 10, 2020 12:16 am
by admin
kev1n,

Your code has been added.

Thanks!


Steven