Data binding
Bind form field data to content.
Use data binding to create dynamic content in your forms. These functions help you bind form field data to Markdown elements and create conditional content blocks.
Inline data binding
Bind form field data directly within Markdown elements using the {$ field $} syntax.
Example
import { Composer } from "formsmd";
const composer = new Composer({
id: "my-form"
});
composer.emailInput("email", {
question: "What's your email address?",
required: true
});
composer.slide({});
composer.h1("Welcome, {$ email $}!");
composer.p("Order confirmation will be sent to {$ email $}.");Generates the following Markdown-like syntax:


Block-level data binding
Create dynamic content blocks that respond to multiple form field values. Use the div() function with the bind parameter to specify which form fields to watch.
Function overview
The following is the overview of the function:
Parameters
bind
Array<string>
The names of the form fields to bind to the division (e.g., ["name", "email"]). Any changes to these fields will trigger updates to the division content.
id
string
The id attribute of the division element.
classNames
string[]
The CSS class names of the division element. See the available CSS utility classes.
attrs
Array<{ name: string, value: string }>
Other HTML attributes of the division element. Each attribute has a name and value property.
Example
Please note, the content inside the <div> elements uses Nunjucks, so its entire list of features such as if-else statements, loops, filters, etc. are fully supported. Of course, Markdown is also supported within the content.
Generates the following Markdown-like syntax:

Group together inputs and content using <div>
<div>Use divStart() and divEnd() functions to create content groups with shared data bindings or styling.
Function overview
The parameters for divStart() are the same as the div() function.
Example
Generates the following Markdown-like syntax:
Last updated
Was this helpful?