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 is the main runtime class for rendering and managing Forms.md forms in the browser. It handles initialization, state management, form submission, and user interactions.
Constructor
Create a new Formsmd instance.The Forms.md template string
The DOM container where the form will be rendered
Configuration options
Properties
The options object passed to the constructor, with defaults applied
The DOM container for the form
The current form state including:
formData: Current form field valuesdata: Data from data blockssettings: Parsed settings from the templateslideData: Information about the current slidefieldTypes: Type information for each fieldbindDivTemplates: Templates for reactive bind divs
Methods
init()
Initialize the form. This renders the template, sets up event listeners, and prepares the form for user interaction.You must call
init() after creating a Formsmd instance to render and activate the form.State Management Methods
setStateToDefaults()
Reset the state to default values.saveFieldValue()
Manually save a form field value to local storage.Field name
Field value to save
removeSavedFormData()
Remove all saved form data from local storage.Color Scheme Methods
setPreferredColorScheme()
Set the preferred color scheme from local storage.toggleColorScheme()
Toggle between light and dark color schemes.The click event from the toggle button
Navigation Methods
nextSlide()
Navigate to the next slide.The currently active slide element
prevSlide()
Navigate to the previous slide.The currently active slide element
Validation Methods
formValid()
Validate a form and add error messages if necessary.The form element to validate
Returns
true if the form is valid, false otherwiseremoveFieldErrors()
Remove all errors from a form field.The form field element
addFieldError()
Add an error message to a form field.The form field element
Unique ID for the error element
Error message to display
Submission Methods
postFormData()
Submit form data to the configured endpoint.Whether to check post conditions before submitting
Whether this is the final submission (end slide)
Promise that resolves to an object with:
ok(boolean): Whether the request succeededjson(object): The response JSON
Data Methods
getRemoteData()
Fetch data from a remote source specified in settings.Promise that resolves to the fetched data as a string
Utility Methods
createRandomId()
Create a random 32-character ID separated by dashes.A randomly generated ID string
getIdPrefix()
Get the prefix for page/form IDs.The ID prefix (empty string if no ID is set)
Event Handler Methods
These methods are automatically attached to form elements during initialization. You can also call them manually if needed.textFieldOnInput()
Handle input events for text fields.numberFieldOnInput()
Handle input events for number fields.selectFieldOnInput()
Handle input events for select fields.choiceFieldOnInput()
Handle input events for choice fields (radio/checkbox).datetimeFieldOnInput()
Handle input events for datetime fields.fileFieldOnInput()
Handle input events for file upload fields.Overridable Methods
These methods can be overridden to customize behavior.getSubmissionErrors()
Extract error messages from a JSON response. Override this to support different error formats.The JSON response from form submission
Array of error message strings
By default, this method assumes OpenAPI error format. Override it to support your API’s error format.
onCompletion()
Called when the user reaches the end slide. Override this to execute custom logic on form completion.The JSON response from the final form submission
Example
Browser Events
The Formsmd class automatically handles the following browser events:- Input events: Updates state and triggers validation
- Submit events: Validates and submits form data
- Click events: Handles navigation, color scheme toggle, and file resets
- Focus events: Manages autofocus behavior
Local Storage
WhensaveState is enabled (default), the following data is stored in local storage:
- Form data: Current values of all form fields
- Response ID: Unique identifier for the current form session
- Color scheme: User’s preferred color scheme