TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/formsmd/formsmd/llms.txt
Use this file to discover all available pages before exploring further.
Formsmd class handles the rendering, initialization, and runtime behavior of your forms. It takes a template string (typically generated by the Composer class) and renders it into a fully functional, interactive form.
Overview
The Formsmd class is responsible for:- Parsing and rendering form templates
- Managing form state and slide navigation
- Handling form submissions and validation
- Managing local storage for form persistence
- Event handling for user interactions
Constructor
Create a new Formsmd instance:src/main.js
Parameters
The Forms.md template string (from Composer or hand-written)
The DOM element where the form will be rendered
Configuration options for rendering and behavior
Options
The options object configures runtime behavior:View all options
View all options
| Option | Type | Default | Description |
|---|---|---|---|
colorScheme | "light" | "dark" | "light" | Initial color scheme |
isFullPage | boolean | false | Whether to render in full page mode |
saveState | boolean | true | Save form data to local storage |
sanitize | boolean | true | Sanitize template content |
startSlide | number | 0 | Index of first slide to show |
footer | "hide" | "show" | - | Control footer visibility |
slideControls | "hide" | "show" | - | Control slide navigation buttons |
pageProgress | "hide" | "show" | "decorative" | - | Control progress indicator |
formsmdBranding | "hide" | "show" | - | Control Forms.md branding |
postData | Object | {} | Extra data to send with POST requests |
postHeaders | Object | {} | Headers for POST requests |
getHeaders | Object | {} | Headers for GET requests |
errorFieldKey | string | "field" | Key for field in error objects |
errorMessageKey | string | "message" | Key for message in error objects |
prioritizeURLFormData | boolean | false | Prioritize URL parameters over saved data |
sendFilesAsBase64 | boolean | false | Convert files to base64 for submission |
themeLight | ThemeType | - | Light theme colors |
themeDark | ThemeType | - | Dark theme colors |
recaptcha | RecaptchaType | - | Google reCAPTCHA v3 configuration |
paddingInlineTop | number | 20 | Top padding for inline forms |
paddingInlineBottom | number | 20 | Bottom padding for inline forms |
paddingInlineHorizontal | number | 0 | Horizontal padding for inline forms |
Initialization
Callinit() to render and initialize the form:
src/main.js
The
init() method must be called after creating the instance to render the form.State management
Formsmd manages internal state for form data, slide navigation, and field types:Resetting state
Reset the form state to defaults:src/main.js
Local storage
By default, Formsmd saves form data to local storage as users fill out the form. This allows users to return to partially completed forms.Disabling state persistence
Manual field value saving
src/main.js
Clearing saved data
src/main.js
Form submission
Formsmd handles form submission via POST requests to the configured endpoint.Basic submission
Handling submission responses
Override theonCompletion method to handle successful submissions:
src/main.js
Custom error handling
OverridegetSubmissionErrors to handle custom error formats:
src/main.js
Event handling
Formsmd automatically adds event listeners for all form interactions:- Form field inputs and changes
- Slide navigation (next/previous)
- File uploads
- Code block copy buttons
- Color scheme toggle
Event listeners are automatically added during initialization. You generally don’t need to manage them manually.
Slide navigation
Formsmd provides methods for programmatic slide control:Navigate to next slide
Navigate to previous slide
Getting next/previous slides
These methods respect jump conditions and logic:src/main.js
Validation
Formsmd handles client-side validation automatically:src/main.js
Field error handling
src/main.js
Theming
Configure light and dark themes:Toggle color scheme
Users can toggle between light and dark modes (if enabled in settings):src/main.js
Google reCAPTCHA
Integrate Google reCAPTCHA v3 for spam protection:Complete example
Next steps
Composer
Learn to build templates with Composer
Slides
Create multi-step forms with slides
Conditional logic
Add dynamic behavior to forms