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">
    <button id="normal" class="btn btn-primary">
      View Submission Normally
    </button>
    <button id="html" class="btn btn-primary">
      View Submission as HTML
    </button>
    <div id="formio"></div>

  </div>
</div>

JavaScript

const viewNormally = () => {
  Formio.createForm(
    document.getElementById("formio"),
    "https://examples.form.io/wizard/submission/5a542c9e2a40bf0001e0f8a9"
  );
}

const viewAsHtml = () => {
  Formio.createForm(
    document.getElementById("formio"),
    "https://examples.form.io/wizard/submission/5a542c9e2a40bf0001e0f8a9", {
      readOnly: true,
      renderMode: "html",
    }
  );
}

document.getElementById("normal").addEventListener("click", viewNormally);
document.getElementById("html").addEventListener("click", viewAsHtml);

viewNormally();