enter the field ID of the field which precedes the spacer
I’ve used this script before with varying success but the bit which always trips me up is what you determine to the the “field ID”. Do you mean simply the number of the field, displayed at the top of the field properties when it is selected (ie 15), the one displayed on the frontend code (ie field_93_15) or the one displayed on the backend code (ie field_15)?
When using that script, you can add simply the digit(s) of the field ID. So, to remove a spacer after Field ID 15, enter 15 when prompted. Here is a modified script that will let you enter multiple field IDs (comma-separated), if you need to remove a number of spacers from the same form.
var removeOrphanedSpacersAfter = window.prompt('Remove orphaned spacer after which field ID(s)?').split(/[ ,]+/);
for ( let i = 0; i < form.fields.length; i++ ) {
if ( removeOrphanedSpacersAfter.includes( form.fields[i].id.toString() ) ) {
let orphanedSpacer = document.getElementById(`field_${form.fields[i].id}`).nextElementSibling;
if ( orphanedSpacer.classList.contains('spacer') ) {
form.fields[i].layoutSpacerGridColumnSpan = 0;
orphanedSpacer.remove();
}
}
}