Double recording of data

Questions related to using nuBuilder Forte.

Double recording of data

Postby mariri » Wed Jan 08, 2020 12:08 am

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 !
Attachments
Double recording of data.JPG
Double recording of data.JPG (36.57 KiB) Viewed 815 times
mariri
 
Posts: 45
Joined: Mon Sep 02, 2019 7:24 pm

Re: Double recording of data

Postby kev1n » Wed Jan 08, 2020 12:35 am

Hi,

Is it possible that the duplicate entries are generated by clicking "Save" 2 times in a row? Is this reproducible for you?
kev1n
 
Posts: 841
Joined: Mon Oct 15, 2018 2:13 am

Re: Double recording of data

Postby mariri » Wed Jan 08, 2020 12:51 am

Ok I tried to record data by clincking several times on the Save button and data was duplicated... :cry:
mariri
 
Posts: 45
Joined: Mon Sep 02, 2019 7:24 pm

Re: Double recording of data

Postby kev1n » Wed Jan 08, 2020 2:32 am

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);
    });
 
}
kev1n
 
Posts: 841
Joined: Mon Oct 15, 2018 2:13 am

Re: Double recording of data

Postby Janusz » Wed Jan 08, 2020 7:16 am

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);');
    }
}
Janusz
 
Posts: 325
Joined: Fri Dec 28, 2018 10:11 pm
Location: Krakow, Poland

Re: Double recording of data

Postby kev1n » Wed Jan 08, 2020 5:55 pm

@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 10:24 pm, edited 2 times in total.
kev1n
 
Posts: 841
Joined: Mon Oct 15, 2018 2:13 am

Re: Double recording of data

Postby Janusz » Wed Jan 08, 2020 6:22 pm

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.
Janusz
 
Posts: 325
Joined: Fri Dec 28, 2018 10:11 pm
Location: Krakow, Poland

Re: Double recording of data

Postby mariri » Wed Jan 08, 2020 10:12 pm

Thanks for ur replies ! It works for me
mariri
 
Posts: 45
Joined: Mon Sep 02, 2019 7:24 pm

Re: Double recording of data

Postby admin » Fri Jul 10, 2020 7:46 am

kev1n,

Your code has been added.

Thanks!


Steven
admin
Site Admin
 
Posts: 3309
Joined: Mon Jun 15, 2009 9:53 am


Return to General