← News
  • Release

Introducing @mnjs/formkit

FormKit inputs, schema, and validation in ordinary Marionette Views. Give the form one job and keep the screen yours.

FormKit for Marionette, now on npm. The two logos sit beside a wireframe showing a form within a larger screen.

A form library should handle the form. It shouldn’t have to take over the app.

@mnjs/formkit 0.2.0 brings FormKit inputs, schema, and validation to Marionette. It runs on FormKit Core without a Vue or React runtime. FormKit owns the values, validation, and submission. Marionette Views and Regions own what goes on screen and when it comes down.

A form can be part of a screen

A lot of forms start with a few fields and a Save button. The interesting ones grow into screens. One section becomes a list you can reorder. Another needs to stay put while you work somewhere else. Eventually you want to change the surrounding UI without rebuilding the thing the user is halfway through filling out.

With @mnjs/formkit, you can show a schema fragment in one Region and a hand-written View in another. Native field Views and schema fields share one FormKit tree, so they can validate and submit together. If a field just needs to be disabled or relabeled, update it in place. When you replace a Region, Marionette cleans up the child View it owned. You decide which parts change.

Here’s one ordinary Marionette form View with a validated email field:

import { View } from 'marionette';
import { attachFormKit } from '@mnjs/formkit';

const ProfileForm = View.extend({
  tagName: 'form',
  attributes: { novalidate: '' },
  template: () => '<div class="email"></div><button>Save</button>',
  regions: { email: '.email' },
  events: { submit: 'save' },

  initialize({ onSubmit }) {
    this.form = attachFormKit(this, { onSubmit });
  },

  onRender() {
    this.showChildView('email', this.form.field({
      name: 'email',
      label: 'Email',
      type: 'email',
      validation: 'required|email',
    }));
  },

  save(event) {
    return this.form.submit(event);
  },
});

Show it in a Region and give it your onSubmit handler. The View owns the layout and the native submit event. The form session handles validation before calling your handler with the values.

What we measured

We built paired implementations of three public examples: a synced list, a Carbon-styled form, and a Kitchen Sink input gallery. In our Chromium runs with @mnjs/formkit 0.1.0, the Marionette versions were 7–15% faster to become ready on a cold local load and had 22–38% less live JavaScript heap after the tested workflows. The biggest absolute difference was in Kitchen Sink: 86 ms sooner to ready and 12.4 MB less live JS heap.

ExampleCold-ready (ms)Live JS heap (MB)
Synced list147.1 → 137.44.07 → 3.19
Carbon196.4 → 179.46.26 → 4.50
Kitchen Sink572.6 → 486.632.81 → 20.43
Vue → Marionette. Lower is better. Heap measured after the tested workflow. Benchmark notes and full results.

The heap figures cover live JavaScript, not total browser memory. Warm edits were generally close, and the synced-list move had no clear winner.

What agents chose

Marionette stood out when reviewers had to follow what changed on a screen and what stayed put. In the synced list, that meant moving a row twice while an edit was still pending. Reviewers chose Marionette for tracing the edit because they could inspect the row’s identity, its position in the list, and the value that gets submitted separately.

Kitchen Sink gave them a different reason to pick Marionette. The gallery and Login are separate Views. Switch back to the gallery and it’s where you left it; open Login again and it starts fresh. The screen decides what to keep, without asking either form to manage the other.

RoundingWell asked Opus and Astra to compare the Vue and Marionette implementations of one of its large, multi-step production forms. Both chose Marionette as the one they’d rather maintain. If your forms are starting to look like screens, give it a try.

Try it

npm install @mnjs/formkit@0.2.0 marionette@^5.2.0

Start with the FormKit authoring guide. It covers field Views, schema fragments, in-place updates, and which parts of FormKit 2.10.0 are supported.