Created
September 12, 2020 14:38
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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("[email protected]"); | |
} 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