{"id":19594541,"url":"https://github.com/toggle-corp/toggle-form","last_synced_at":"2026-03-08T04:31:37.635Z","repository":{"id":42629186,"uuid":"355482340","full_name":"toggle-corp/toggle-form","owner":"toggle-corp","description":"React form library","archived":false,"fork":false,"pushed_at":"2025-03-16T07:26:51.000Z","size":982,"stargazers_count":4,"open_issues_count":10,"forks_count":0,"subscribers_count":4,"default_branch":"develop","last_synced_at":"2025-11-02T22:13:27.205Z","etag":null,"topics":["form","react","react-hooks","typesafe","validation"],"latest_commit_sha":null,"homepage":"https://develop--606ec3c837e5de00219eb646.chromatic.com","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/toggle-corp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-04-07T09:14:24.000Z","updated_at":"2024-05-16T10:14:10.000Z","dependencies_parsed_at":"2023-01-27T18:01:23.810Z","dependency_job_id":"1f396035-6c87-429c-96be-acb51a46f81b","html_url":"https://github.com/toggle-corp/toggle-form","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/toggle-corp/toggle-form","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toggle-corp%2Ftoggle-form","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toggle-corp%2Ftoggle-form/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toggle-corp%2Ftoggle-form/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toggle-corp%2Ftoggle-form/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/toggle-corp","download_url":"https://codeload.github.com/toggle-corp/toggle-form/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toggle-corp%2Ftoggle-form/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30245215,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-08T00:58:18.660Z","status":"online","status_checked_at":"2026-03-08T02:00:06.215Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["form","react","react-hooks","typesafe","validation"],"created_at":"2024-11-11T08:43:54.120Z","updated_at":"2026-03-08T04:31:37.619Z","avatar_url":"https://github.com/toggle-corp.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Toggle Form\n\nA simple form library using react hooks\n\n## Features\n\n- Reasonably typesafe\n- Powerful validation\n- Supports nested forms\n- Supports conditional fields\n- Supports automatic dependency tracking\n- Supports restore point\n\n## API\n\nThe library exposes three react hooks to define a form.\n\n1. useForm\n2. useFormArray\n3. useFormObject\n\n### useForm\n\n`useForm` hook is used to control a form.\nThe `useForm` hook accepts these arguments:\n\n|argument|description|\n|----|----|\n|schema|The schema used to validate the form|\n|initialState|The initial state for the form|\n|context|The external context for form|\n\nThe return value from `useForm` hooks are as follows:\n\n|value|description|\n|----|----|\n|value|The value of the form|\n|error|The error state of the form|\n|pristine|True if the form is pristine|\n|setPristine|Defines if the form is pristine|\n|validate|If there are errors, sets form error else returns sanitized value|\n|setPristine|Function to set form's pristine state|\n|setError|Function to set form's error state|\n|setValue|Function to set form's value, error is cleared and pristine is set to true|\n|setFieldValue|Function to set form field's value and pristine is set to false|\n|hasRestorePoint|True if there is a restore point|\n|restorePointValue|Value of the form when restore point was created|\n|restorePointError|Error of the form when restore point was created|\n|restorePointPristine|Pristine stateof the form when restore point was created|\n|createRestorePoint|Function to create restore point|\n|restore|Function to restore state to last restore point|\n|clearRestorePoint|Function to clear last restore point|\n\n### useFormObject\n\n`useFormObject` hook is used to control an object.\nThe `useFormObject` hook accepts these arguments:\n\n|argument|description|\n|----|----|\n|name|name of the object field|\n|onChange| change handler of the object|\n|defaultValue|default value for the object|\n\nThe return value from `useFormObject` is the change handler for the object\nfields.\n\n### useFormArray\n\n`useFormArray` hook is used to control an array.\nThe `useFormArray` hook accepts these arguments:\n\n|argument|description|\n|----|----|\n|name|name of the array field|\n|onChange| change handler of the array|\n\nThe return value from `useFormArray` are as follows:\n\n|value|description|\n|----|----|\n|setValue|The change handler for the array items.|\n|removeValue|The delete handler for the array items.|\n\n### Schema\n\nThe schema defines the structure of the form.\nThe schema can defined for objects, arrays and literals.\n\n### Object Schema\n\nThe schema object is an object with these properties:\n\n|property|description|\n|----|----|\n|validation|Function to validate the object|\n|fields|Function that defines the schema for each key of the object|\n\n### Array Schema\n\nThe array schema is an object with these properties:\n\n|property|description|\n|----|----|\n|validation|Function to validate the array|\n|member|Function that defines the schema for each item of the array|\n|keySelector|Function that defines the unique key for each item of the array|\n\n### Literal Schema\n\nThe literal schema is an object with these properties:\n\n|property|description|\n|----|----|\n|required|If defined, the literal will be required|\n|requiredValidation|If defined, this function will be used to check required condition|\n|defaultValue|If defined, the literal value will fallback to this value|\n|forceValue|If defined, the literal value will always be this value|\n|validations|Array of functions to validate the literal|\n\n### Validation functions\n\nThe library provides these validation function:\n\n- requiredCondition\n- requiredStringCondition\n- requiredListCondition\n- blacklistCondition\n- whitelistCondition\n- lengthGreaterThanCondition\n- lengthSmallerThanCondition\n- greaterThanCondition\n- smallerThanCondition\n- greaterThanOrEqualToCondition\n- lessThanOrEqualToCondition\n- integerCondition\n- emailCondition\n- urlCondition\n\n## Helper Functions\n\n### getErrorObject\n\nFunction to convert leaf error to object error\n\n### getErrorString\n\nFunction to convert object error or array error to string error\n\n### removeNull\n\nFunction to recursively remove `null` values from an object\n\n### createSubmitHandler\n\nPredefined function to define submit handler for html form\n\n|argument|description|\n|----|----|\n|validator|Function to trigger form validation|\n|setError|Function to set form error|\n|successCallback|Callback for validation success|\n|failureCallback|Callback for validation failure|\n\nThe return value is the function that can be passed to form `onSubmit` prop\n\n### addCondition\n\nPredefined function to add conditions on schema fields\n\n|argument|description|\n|----|----|\n|schema|Fields of the object schema|\n|value|Value of the object|\n|dependentKeys|Keys of the object that are used to define the condition|\n|valueKeys|Keys of the object that are affected by the condition|\n\nThe return value is the updated fields of the object schema\n\n## Core Functions\n\n### accumulateValues\n\nFunction to get validated value from form value and form schema\n\n### accumulateErrors\n\nFunction to get form error from form value and form schema\n\n### accumulateDifferentialErrors\n\nFunction to get differential form error from form value and form schema\n\n### analyzeErrors\n\nFunction to identify if form has errored from the form error\n\n## Symbols\n\n### nonFieldError\n\nSymbol to access non field error on errors returned by `useForm`\n\n### fieldDependencies\n\nSymbol to define field dependencies on object schema\n\n### undefinedValue\n\nSymbol to define `undefined` on `forceValue` and `defaultValue` on literal schema\n\n### nullValue\n\nSymbol to define `null` on `forceValue` and `defaultValue` on literal schema\n\n## Development\n\n```bash\n# Install dependencies\nyarn install\n```\n\n### Lib\n\n```bash\ncd lib\n\n# Eslint\nyarn lint\n\n# Typescript\nyarn typecheck\n\n# Check unused files\nyarn check-unused\n\n# Test\nyarn test\n```\n\n### Storybook\n\n```bash\ncd storybook\n\n# Start storybook\nyarn storybook\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoggle-corp%2Ftoggle-form","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftoggle-corp%2Ftoggle-form","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoggle-corp%2Ftoggle-form/lists"}