Returns true if the value of the specified field is "on", otherwise
false.
The name of the form field.
A boolean representation of the form field value.
Retrieves the value of the specified form field as a File object.
The name of the form field.
The File object associated with the key.
Retrieves all File objects associated with the specified form field as
an array.
The name of the form field.
An array of File objects associated with the key.
Checks if the given key exists in the FormData.
The name of the form field.
true if the key exists, otherwise false.
Retrieves the value of the specified form field as a number.
The name of the form field.
The number value associated with the key.
Retrieves all string values associated with the specified form field as an array.
The name of the form field.
An array of string values associated with the key.
The
FormParseris a specialized parser designed to safely extract and validate values from aFormDataobject. It provides methods to retrieve form fields in a type-safe manner, ensuring that required fields are present and properly typed.This parser is particularly useful when handling form submissions, such as in a Remix action, where structured validation of form data is necessary.
Usage
FormParserwraps theFormDataobject and provides methods to:has).The parser uses custom error types (
MissingKeyError,InvalidTypeError,InvalidInstanceOfError) to simplify debugging and enforce validation rules.How It Works
string,file, andbooleanvalidate and return the form data in the correct type.stringArrayandfileArraycan be used to retrieve arrays of values."on"is consideredtrue, and all others arefalse.Example