VanillaJS Form.io
by brendanbond
HTML
<script src="https://unpkg.com/[email protected]/dist/formio.full.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/formio.full.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<div class="page-content">
<div class="container-fluid">
<div id="formio"></div>
</div>
</div>
JavaScript
var components = {
components: [
{
type: 'textfield',
key: 'firstName',
label: 'First Name',
placeholder: 'Enter your first name.',
input: true,
tooltip: 'Enter your <strong>First Name</strong>',
description: 'Enter your <strong>First Name</strong>'
},
{
type: 'textfield',
key: 'lastName',
label: 'Last Name',
placeholder: 'Enter your last name',
input: true,
tooltip: 'Enter your <strong>Last Name</strong>',
description: 'Enter your <strong>Last Name</strong>'
},
{
type: "select",
label: "Favorite Things",
key: "favoriteThings",
placeholder: "These are a few of your favorite things...",
data: {
values: [
{
value: "raindropsOnRoses",
label: "Raindrops on roses"
},
{
value: "whiskersOnKittens",
label: "Whiskers on Kittens"
},
{
value: "brightCopperKettles",
label: "Bright Copper Kettles"
},
{
value: "warmWoolenMittens",
label: "Warm Woolen Mittens"
}
]
},
dataSrc: "values",
template: "<span>{{ item.label }}</span>",
multiple: true,
input: true
},
{
type: 'button',
action: 'submit',
label: 'Submit',
theme: 'primary'
}
]
};
Formio.createForm(document.getElementById('formio'), components).then((form) => {
// the `initialize` event fires when we're initialized
form.on("initialized", () => console.log("Initialized!"));
console.log(form);
// the `render` event has already fired (we're rendered!) but will
// fire again if we redraw
form.on("render", () => console.log("Rendered!"));
// uncomment the line below to rerender
// form.redraw();
});