asked on March 14, 2024
This code that runs on 3 tables Master Permits, Permits, and Sub Permits. It is executing multiple times per table row on the Master and Sub tables. Resulting in duplicate <p>'s. The Permits table only executes once as expected. All 3 tables have the class permit, one field with the class permitNumber, and one field with the class formsResLink. The sub permit fields are currently shown to verify that only one distinct row is retrieved from the lookup.
$(document).ready(function () { //Set Create Inspection href $('.createInspectionLink a').prop('href', "https://Somewherelf.com/Forms/DEVInspections?Submitted_By=" + $('.initiator input').val() + "&Permit_Number=" + $('.startingPermit input').val() + "&Location=" + $('.location input').val() + "&Permit_EntryID=" + $('.entryID input').val() + "&Permit_Id=" + $('.thisPermitId input').val() + "&Document_Type=Permit"); $('.permit').on("change", ".permitNumber input", function () { createPermitLink.call(this); }); $('.permit').on("change", ".formsResLink input", function () { createPermitLink.call(this); }); }); function createPermitLink(inputField) { var tableRow = $(this).closest('tr') var permitNumber = tableRow.find('.permitNumber input').val(); var resLink = tableRow.find('.formsResLink input').val(); var workClass = tableRow.find('.workClass input').val(); var thisVal = $(this).val(); if ((resLink == '') && (thisVal !== resLink)) { console.log(tableRow.find('.permitlink')); tableRow.find('a').remove(); tableRow.find('p').remove(); tableRow.find('.formsResLink input').after($('<p class="permitlink">' + permitNumber + ' - ' + workClass + ' (Finaled)</p>')); //alert(permitNumber + ' - ' + workClass + ' (Finaled)</p>'); tableRow.find('.formsResLink input').hide(); } if ((resLink !== '') && (thisVal !== permitNumber)) { tableRow.find('a').remove(); tableRow.find('p').remove(); tableRow.find('.permitlink').remove(); $(this).after($('<a class="permitlink" href="' + resLink + '" target="_blank">' + permitNumber + ' - ' + workClass + '</a>')); //alert(resLink + '" target="_blank">' + permitNumber + ' - ' + workClass + '</a>'); $(this).hide(); } //Hide Table Row delete X's $('.permit td.action').hide(); $('.permit td.col0, .cf-col-label').hide(); //Hide Table Row add links $('.permit .cf-table-add-row').hide(); }
0
0