Skip to content

Instantly share code, notes, and snippets.

@marklchaves
Created June 1, 2022 02:44
Show Gist options
  • Save marklchaves/5c400b1e4590d249bb34d8c5a62dd206 to your computer and use it in GitHub Desktop.
Save marklchaves/5c400b1e4590d249bb34d8c5a62dd206 to your computer and use it in GitHub Desktop.
Find all forms and flag forms with no IDs
let firstNoId = true;
let forms = [];
let noIds = [];
let out = "";
/** Place a border around forms with no ID set. */
document.querySelectorAll("form").forEach((f) => {
if (!f.hasAttribute("id")) {
if (firstNoId) {
firstNoId = false;
f.scrollIntoView();
}
f.style.outline = "3px solid orangered";
noIds.push(f);
}
forms.push(f);
out += (f.getAttribute("id") || 'No ID') + '\n';
});
if (forms.length > 0) {
const plural = forms.length > 1 ? "s" : "";
console.info(`%cFound %d form${plural}.`, 'color: limegreen', forms.length);
console.groupCollapsed('All forms');
forms.forEach(f => {console.dirxml(f)});
console.groupEnd('All forms');
copy(out);
console.info("Ready to paste all form IDs.");
}
if (noIds.length > 0) {
const plural = noIds.length > 1 ? "s" : "";
console.warn(`%cFound %d form${plural} with no ID.`, 'color: orangered', noIds.length);
console.groupCollapsed('Forms with no ID');
noIds.forEach(f => {console.dirxml(f)});
console.groupEnd('Forms with no ID');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment