Clara Form

Medical form web component: <clara-form> in plain HTML, Vue, Angular or anything else

Add a medical form to any page with the clara-form web component: one CDN script, template and theme attributes, custom events and Shadow DOM isolation.

Loading the preview…

HTML
<!-- The CDN script registers <clara-form> and defines window.ClaraForm -->
<script src="https://cdn.clara.care/form/latest.js"></script>

<style>
  /* Theme from the host page: the variables cross the Shadow DOM boundary. */
  clara-form { --clara-form-primary: #0f766e; --clara-form-radius: 6px; }
</style>

<main class="demo demo-split">
  <section>
    <!-- template-id + api-key load a template from Clara Platform; here the template is set as a property -->
    <clara-form lang="en" theme="auto" submit-label="Submit"></clara-form>
    <p class="demo-actions"><button type="button" id="fill">setFieldValue('blood_pressure', '118/76')</button></p>
  </section>

  <section class="demo-out" aria-labelledby="log-h">
    <h2 id="log-h">Events</h2>
    <pre id="log" aria-live="polite"></pre>
  </section>
</main>

Every value on this page is synthetic. Never paste real patient data into a public page.

How it works

  1. Load the script

    <script src="https://cdn.clara.care/form/2.0.0/clara-form.js"> registers the element. From npm: import '@clara.care/form/element'.

  2. Place the element

    <clara-form lang theme submit-label> with template-id and api-key, or set the template object as the template property for an offline form.

  3. Listen to events

    clara-ready, clara-change, clara-invalid and clara-submit bubble and are composed, so you can listen on the element or on document.

  4. Call its methods

    setFieldValue, getValues, validate, submit, reset, toJSON and toFhir are methods of the element.

A web component works in any stack: plain HTML, Vue, Angular, Svelte, a legacy server-rendered page or a CMS. The CDN script registers <clara-form>; you configure it with attributes, set the template as a property and listen to its custom events. Styles live in a Shadow DOM, so your page's CSS and the form's never collide.

This example ports the HTML example of the @clara.care/form package: an events log, a button that sets a value from the page, and a theme variable that crosses the Shadow DOM boundary.

Vue and Angular

Tell the framework that clara-form is a custom element and bind the template as a property. In Vue: isCustomElement in the compiler options and :template.prop. In Angular: CUSTOM_ELEMENTS_SCHEMA and [template]. Events are listened to with the usual @clara-submit or (clara-submit).

Vue
<script setup>
import '@clara.care/form/element';
const template = { /* … */ };
const onSubmit = (e) => save(e.detail.fhir);
</script>
<template>
  <clara-form :template.prop="template" lang="en" @clara-submit="onSubmit" />
</template>

Theming across the Shadow DOM

CSS custom properties inherit into the shadow root: set --clara-form-primary, --clara-form-radius or --clara-form-font on the element or any ancestor. theme="dark" or "auto" switches the palette; each variable has a -dark twin.

Questions about this example

Do I need React to use the web component?

Not in your code. The CDN script bundles everything it needs. If you install from npm, react and react-dom are peer dependencies the element uses internally; your app does not have to be written in React.

How do I pass the template without an API key?

Set the template property to the object, or the template attribute to its JSON. The form renders without any network call. template-id with api-key loads it from Clara Platform instead.

Can my CSS style the inside of the form?

The form renders in a Shadow DOM, so page selectors do not reach it. Use the CSS variables for colors, radius and font, and the part="root" container for coarse adjustments. The CDN init() script without shadow renders in the light DOM if you prefer plain classes.

Which events does <clara-form> emit?

clara-ready, clara-change, clara-submit, clara-invalid, clara-error, clara-secondary-action, clara-autosave, clara-submitted, clara-submit-error, clara-live-status, clara-live-update and the widget ones. All are CustomEvents with bubbles and composed.

Does it work in a CMS or a legacy page?

Yes. Any page that can include a script tag can use it, including server-rendered templates and page builders that allow custom HTML. Register the page's origin as a widget site in Clara Platform if you load templates by id.

Planning an integration?

Tell us about your system and your forms. We run small pilots with technology partners.

Cookie settings

Choose which optional cookies Clara Care may use. They stay off until you turn them on, and you can change your choice at any time from Cookie settings in the footer. Privacy policy