Skip to content

Instantly share code, notes, and snippets.

@craigwendel
Created June 9, 2017 16:12
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 craigwendel/de61e24e6c2b53450cbec678eb7946b8 to your computer and use it in GitHub Desktop.
Save craigwendel/de61e24e6c2b53450cbec678eb7946b8 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Form Builder</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header>
<span>Sign Up For My Web App</span>
</header>
<fieldset>
</fieldset>
<footer>
<div class="submit-button">
<input type="submit" name="submit-button" id="submit-button" value="Submit Form">
</div>
</footer>
<script src="main.js" charset="utf-8"></script>
</body>
</html>
var formData = [
{
"type": "text",
"label": "First Name",
"id": "user-first-name",
"icon": "fa-user",
"options": []
},
{
"type": "text",
"label": "Last Name",
"id": "user-last-name",
"icon": "fa-user",
"options": []
},
{
"type": "email",
"label": "Email Address",
"id": "user-email",
"icon": "fa-envelope",
"options": []
},
{
"type": "text",
"label": "Current website url",
"id": "user-website",
"icon": "fa-globe",
"options": []
},
{
"type": "select",
"label": "Select Language",
"id": "user-language",
"icon": "",
"options": [
{
"label": "English",
"value": "EN"
},
{
"label": "French",
"value": "FR"
},
{
"label": "Spanish",
"value": "SP"
},
{
"label": "Chinese",
"value": "CH"
},
{
"label": "Japanese",
"value": "JP"
}
]
},
{
"type": "textarea",
"label": "Your Comment",
"id": "user-comment",
"icon": "fa-comments",
"options": []
},
{
"type": "tel",
"label": "Mobile Number",
"id": "user-mobile",
"icon": "fa-mobile-phone",
"options": []
},
{
"type": "tel",
"label": "Home Number",
"id": "user-phone",
"icon": "fa-phone",
"options": []
}
];
/* START HERE */
let fieldset = document.querySelector('fieldset')
for (let i = 0; i < formData.length; i++) {
if (formData[i].type === "select") {
let select = document.createElement('select')
select.label = formData[i].label
select.id = formData[i].id
fieldset.appendChild(select)
let disable = document.createElement('option')
disable.label = 'Select language...'
disable.disabled = true;
disable.selected = true;
select.appendChild(disable)
for (n=0; n < formData[i].options.length; n++) {
let option = document.createElement("option")
option.label = formData[i].options[n].label
option.value = formData[i].options[n].value
select.appendChild(option)
}
} else if (formData[i].type === "textarea") {
let text = document.createElement('textarea')
text.label = formData[i].label
text.id = formData[i].id
text.rows = 5
text.placeholder = formData[i].label
fieldset.appendChild(text)
} else {
let input = document.createElement('input')
input.type = formData[i].type
input.label = formData[i].label
input.id = formData[i].id
input.placeholder = formData[i].label
fieldset.appendChild(input)
}
}
/*
Sample colors used:
dark-blue: #4189C7
grey: #D0D4D7
light-blue: #C9DEF0
*/
body {
border: groove;
}
header {
background-color: #4189C7;
color: #ffffff;
font-size: 2.5rem;
height: 15vh;
margin-bottom: 3%;
display: flex;
}
span {
font-family: Arial;
font-weight: 100;
margin-left: 5%;
margin-top: 2.5%;
}
fieldset {
display: flex;
flex-direction: column;
border: 0;
}
input {
padding: 2%;
margin: 2.5%;
border: groove;
width: 90%;
font-size: 1rem;
}
#user-language {
padding: 2%;
margin: 2.5%;
width: 94.5%;
border: groove;
font-size: 1rem;
}
#user-language option {
padding: 1.5%;
}
#user-comment {
padding: 2%;
margin: 2.5%;
width: 90%;
border: groove;
font-size: 1rem;
}
footer {
background-color: #C9DEF0;
height: 15vh;
}
#submit-button {
width: 15%;
color: #ffffff;
background-color: #4189C7;
text-align: center;
border: 0;
font-size: 1.25rem;
border-radius: 2px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment