Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Double recording of data

Questions related to using nuBuilder Forte.
Post Reply
mariri
Posts: 45
Joined: Mon Sep 02, 2019 11:54 am

Double recording of data

Unread post 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 !
You do not have the required permissions to view the files attached to this post.
kev1n
nuBuilder Team
Posts: 4307
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 448 times
Contact:

Re: Double recording of data

Unread post 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?
mariri
Posts: 45
Joined: Mon Sep 02, 2019 11:54 am

Re: Double recording of data

Unread post by mariri »

Ok I tried to record data by clincking several times on the Save button and data was duplicated... :cry:
kev1n
nuBuilder Team
Posts: 4307
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 448 times
Contact:

Re: Double recording of data

Unread post 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);
    });
  
}
Janusz
nuBuilder Team
Posts: 506
Joined: Fri Dec 28, 2018 1:41 pm
Location: Krakow, Poland
Has thanked: 8 times
Been thanked: 18 times

Re: Double recording of data

Unread post 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);');
    }
}
If you like nuBuilder, please leave a review on SourceForge
kev1n
nuBuilder Team
Posts: 4307
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 448 times
Contact:

Re: Double recording of data

Unread post 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();

}
Last edited by kev1n on Wed Jan 08, 2020 1:54 pm, edited 2 times in total.
Janusz
nuBuilder Team
Posts: 506
Joined: Fri Dec 28, 2018 1:41 pm
Location: Krakow, Poland
Has thanked: 8 times
Been thanked: 18 times

Re: Double recording of data

Unread post 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.
If you like nuBuilder, please leave a review on SourceForge
mariri
Posts: 45
Joined: Mon Sep 02, 2019 11:54 am

Re: Double recording of data

Unread post by mariri »

Thanks for ur replies ! It works for me
admin
Site Admin
Posts: 2815
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: Double recording of data

Unread post by admin »

kev1n,

Your code has been added.

Thanks!


Steven
Post Reply