VanillaJS Form.io Renderer
by brendanbond
HTML
<script src="https://unpkg.com/formiojs@latest/dist/formio.full.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/formiojs@latest/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
const formDefinition = {
components: [{
type: "textfield",
input: true,
key: "player",
label: "Player"
},
{
type: "number",
input: true,
key: "number",
label: "Number"
},
{
label: "Show Submission",
action: "custom",
key: "showSubmission",
type: "button",
custom: "showSubmission(data)"
}
],
settings: {},
properties: {},
}
Formio.createForm(document.getElementById('formio'), formDefinition).then(function(form) {
form.on('change', ({
changed: {
component,
value
}
}) => {
if (!value) {
form.submission.data[component.key] = null;
}
})
});
const showSubmission = (data) => console.log(data);