Submitting form by JS causes two rows pointing to the same record in list

longlam

Member
I have several dropdown elements which when changed automatically submit (save) the form. This is to prevent users from forgetting to save once they have selected the drop down.
Problem is for some reason this is creating a second row in the list that points to the same record (See attached). If I log in under another user the duplicated row is still there.

Code being used is: document.forms["form_23"].submit();

Should I be using something else? Is there a different code I can use to save and stay on the form?

Thanks
 

Attachments

  • JS form submit issue.jpg
    JS form submit issue.jpg
    90.2 KB · Views: 149
You screenshot doesn't show the id, so is it really the same record or two records with the same content?

Do you have the id (PK) element published, writable to the user?
What is stored in the database?
 
Is this in an AJAX context? Popup or content plugin?

That's pretty much what I would expect if you submit a new form that way, and then redirect back to the same page, as you'll still be loading the form without a rowid.

You might be able to do it with ...

Code:
Fabrik.getBlock('form_2s').mockSubmit('apply');

... which will act as if the apply button has been clicked, which will submit the form then reload it with the newly created rowid.

-- hugh
 
Hi Guys,

Troester: Yes the two rows link to the same record. If I go click into or hover my mouse over each link you can see they point to the same row id. ... Just wasn't sure how to show that in a screenshot.

Hugh: not sure what you mean by AJAX context, but it basically I have 5 dropdowns which ask the users whether they've completed their section. When the user changes the dropdown to 'yes' then the form submits. Only happens with the first dropdown submit. Subsequest changes to the other dropdowns don't create any further duplicate rows. Code below:

function agreement(x)
{
var elementID = x.element.get('id');
var val = document.getElementById(elementID).options[document.getElementById(elementID).selectedIndex].value;
/*Check if dropdown has been set to yes*/
if(val=='Yes')
/*Ask for confirmation*/
{var response=confirm("You are about to digitally confirm that you have filled in all relevant sections. This cannot be undone. Are you sure?");
if (response==true)
{
var currentdetails = document.getElementById("idps___audit_details").value;
var user = document.getElementById("idps___user_name").value;
var dropdownID = x.element.get('id');
var filledoraccept = dropdownID.substring(7,8);
var section =dropdownID.slice(-1);
var ts = new Date();
var yy1= ts.getFullYear();
var mm1= ts.getMonth()+1;
var dd1= ts.getDate();
var hh= ts.getHours();
var mm= ts.getMinutes();
if(mm1<10){var mm1="0"+mm1;}
if(dd1<10){var dd1="0"+dd1;}
if(mm<10){var mm="0"+mm;}
if(hh<10){var hh="0"+hh;}
var tsdisp=yy1+"-"+mm1+"-"+dd1+" at "+hh+":"+mm;
if(filledoraccept == "f")
{if(section == "F")
{var txt = "Final Rating filled by ";}
else
{var txt = "Initial Form filled by ";}}
else
{var txt = "Final Ratings Accepted by ";}


document.getElementById("idps___audit_details").value = currentdetails+"\n|| "+txt+user+" on "+tsdisp;
document.forms["form_23"].submit();
}
else
{document.getElementById(elementID).selectedIndex = 0;}/*Change dropdown to NO*/
}
else
{document.getElementById(elementID).selectedIndex = 0;}


I'll give your code above a test and see what happens.
 
Was just doing some more testing. Realised it's not my JS that is causing the issue but the repeat groups. Hugh's post earlier prompted me to test that aspect. So... each time I add a new repeat group, when I save, I get an extra row in the list view. So if I repeat the same group 10 times... I get 10 rows.
 
And because I have 2 different repeat groups the number of rows multiplies.
e.g.
Repeat Group 1 => repeated 4 times
Repeat Group 2 => repeated 2 times
Number of times same row repeated in List View => 4 x 2 = 8
 
Cool. That seems to have fixed the issue! Thanks guys!
Good to know that it wasn't a bug, just my lack of knowledge

Thanks again!
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top