Skip to content

Instantly share code, notes, and snippets.

@dkrusky
Created September 12, 2020 14:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dkrusky/12b4343e7dd4d1d454315e67a1785d22 to your computer and use it in GitHub Desktop.
Save dkrusky/12b4343e7dd4d1d454315e67a1785d22 to your computer and use it in GitHub Desktop.
Automatically fill out a webform UI with test data. (supports: select, text, checkbox, textarea, radio)
// tested with jQuery 3.x
$(document).ready(function(){
$("[name^=entry]").each(function(){
switch($(this).prop("type")) {
case "radio":
$(this).prop("checked", true);
break;
case "checkbox":
$(this).prop("checked", true);
break;
case "text":
if($(this).attr("id") == "emailAddress") {
$(this).val("lorumipsum@lorumipsum.com");
} else {
$(this).val("lorum ipsum");
}
break;
case "textarea":
$(this).val("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed quis molestie sem. In interdum neque in magna vulputate tempus. Integer viverra sapien leo, sed rhoncus.");
break;
case "select-one":
$(this).find("option:last").prop("selected", true);
break;
case "select-multiple":
$(this).find("option:last").prop("selected", true);
$(this).find("option:first").prop("selected", true);
break;
default:
console.log( $(this).prop("type") + " is unknown" );
break;
}
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment