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="jumbotron">
  <div class="container text-center">
    <h1>VanillaJS <a href="https://github.com/formio/formio.js" target="_blank">Form Renderer</a></h1>
    <p>by <a target="_blank" href="https://form.io"><img src="https://help.form.io/assets/formio-logo.png" /></a></p>
  </div>
</div>
<div class="page-content">
  <div class="container-fluid">
    <div id="formio"></div>
  </div>
</div>

JavaScript

// RE
console.log('Formio version', Formio.version);
const formDef = {
    "_id": "634fbcc162bfa45394b8a30a",
    "name": "gebBeslissingRvvb001",
    "path": "gebbeslissingrvvb001",
    "type": "form",
    "title": "GEB_BESLISSING_RVVB_001",
    "display": "form",
    "components": [
        {
            "key": "BeslissingDatum",
            "type": "textfield",
            "input": true,
            "label": "Datum van de uitspraak:",
            "widget": {
                 "type": 'calendar',
      		 "format": 'dd.MM.yyyy',
      		 "dateFormat": 'yyyy-MM-dd',
      		 "enableTime": false,
      		 "enableDate": true,
            },
            "validate": {
                "required": true
            },
            "tableView": false,
            "labelWidth": 50,
            "spellcheck": false,
            "labelMargin": 5
        },
        {
            "type": "button",
            "label": "Submit",
            "key": "submit",
            "disableOnInvalid": true,
            "input": true,
            "tableView": false
        }
    ]
};

const options = {
language: 'nl',
hide:{
submit: true,
}
}

Formio.createForm(document.getElementById('formio'), formDef, options).then(function(form) {
  // Defaults are provided as follows.
	console.log('form initialized')
  form.submission = {
    data: {
      BeslissingDatum: '2023-06-02',
    }
  };
  
  // Register for the submit event to get the completed submission.
  form.on('submit', function(submission) {
    console.log('Submission was made!', submission);
  });
  
  // Everytime the form changes, this will fire.
  form.on('change', function(changed) {
    console.log('Form was changed', changed);
  });
});