Installations
npm install form-capacitor
Developer Guide
Typescript
No
Module System
CommonJS, UMD
Score
40.2
Supply Chain
77.4
Quality
81.5
Maintenance
100
Vulnerability
99.6
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (99.8%)
Makefile (0.2%)
Developer
nucleuslabs
Download Statistics
Total Downloads
75,234
Last Day
9
Last Week
60
Last Month
364
Last Year
2,415
GitHub Statistics
3 Stars
227 Commits
6 Watching
11 Branches
6 Contributors
Package Meta Information
Latest Version
1.3.0
Package Id
form-capacitor@1.3.0
Unpacked Size
605.04 kB
Size
165.12 kB
File Count
9
Publised On
09 Mar 2023
Total Downloads
Cumulative downloads
Total Downloads
75,234
Last day
200%
9
Compared to previous day
Last week
-77.4%
60
Compared to previous week
Last month
104.5%
364
Compared to previous month
Last year
-70.9%
2,415
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
40
form-capacitor
Form capacitor is a set of React Hooks that help you manage state, validation and errors for react based forms. This project makes use of mobx / mobx-state-tree for state management and AJV for validation.
Use json-schema to define the state and validation rules for your form then use a few simple Hooks to setup your form state management and validation.
Project Status: A few fun code reviews away from MVP
The @latest version of this project now has reasonable test coverage using some complex form samples with react-testing-library and will soon be considered stable.
Installation
For form-capacitor react 16.8
and react-dom 16.8
are peer dependencies as hooks are required
1yarn add react 2yarn add react-dom 3yarn add form-capacitor
Usage
This is has changed considerably and I will be working on rewriting the docs soon.
Helper methods
These are the core methods that are used to interact with the underlying mobx-state-tree. Also a function that can help formating error messages.
- getValue(obj, path) - gets a value in a mobx state tree or observable map tree based on a path array
- setValue(obj, path, value) - sets a value in a mobx state tree or observable map tree based on a path array
Error Map Methods
- getFlattenedErrors(ErrorMap, path = []) <- This method is useful. The others.. meh... not so much.
- getErrors(ErrorMap, path = [])
- getErrorNode(ErrorMap, path = [])
- setError(ErrorMap, path = [], errorObj)
- setErrors(ErrorMap, path = [], errorObj)
json-schema Definition for your form
Create a definition file for your form including any validation rules.
{
"$schema": "http://json-schema.org/draft-07/schema",
"definitions": {
"SimpleForm": {
"title": "Simple Form",
"description": "Basic Form to test form-capacitor without a lot of external stuff",
"type": "object",
"properties": {
"firstName": {
"errorMessage": "Please type a name which consists of words",
"type": "string",
"title": "First Name",
"pattern": "\\w",
"required": [
"firstName"
]
},
"lastName": {
"errorMessage": "Please type a name which consists of words",
"type": "string",
"title": "Last Name",
"pattern": "\\w"
}
},
"required": [
"firstName"
]
}
}
}
State Management
Form-capacitor uses mobx 4 (for IE support) and a mobx-state-tree to manage form state. This style of observable based state management allows you to develop forms that only re-render input components where the state has changed for the inputs affected by the User interactions. The data for the form is pre generated into a mobx state tree from the json-schema and then
Form definition using json-schema
The reason we chose json-schema to define each form is so that we could have the same validation standard for forms in the browser as the back end service which consumes the data.
Validation
Validation can be As You Type or onEvent or Both it is up to you.
As You Type Validation
Ajv is used to validate data based on the underlying json-schema for the form. The schema is broken up into related elements so that re-renders for error-highlighting and field level error messages is somewhat smart during as you type validation... which you don't have to use The validation only renders the error state for fields who's error state has changed due to a change in the underlying data which triggers a change in the validity of the field.
onEvent Imperative Validation
The schema decorator passes a validation function as a prop to a form component decorated with the schema decorator that will fully validate the entire form data. This works nice if you want to roll your own imperative validation on submit or change in focus or whatever.
Errors
Errors can be managed at the consumer/input level via useFieldErrors
or at the form provider level via the props.errorMap observable map tree.
ThegetFlattenedErrors
function included in form-capacitor will turn errorMap Tree
into a flat array of error objects.
Testing
Run make test
to run all the tests.
some todos:
- Test json-schema array type Tuple Validation (https://json-schema.org/understanding-json-schema/reference/array.html#tuple-validation)
- Test json-schema
allOf
keyword - L18N support for error messages
No vulnerabilities found.
Reason
security policy file detected
Details
- Info: security policy file detected: SECURITY.md:1
- Info: Found linked content: SECURITY.md:1
- Info: Found disclosure, vulnerability, and/or timelines in security policy: SECURITY.md:1
- Info: Found text in security policy: SECURITY.md:1
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
Found 3/17 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/ci.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:23: update your workflow using https://app.stepsecurity.io/secureworkflow/nucleuslabs/form-capacitor/ci.yml/master?enable=pin
- Info: 0 out of 1 GitHub-owned GitHubAction dependencies pinned
Reason
license file not detected
Details
- Warn: project does not have a license file
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 16 are checked with a SAST tool
Reason
24 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-x9w5-v3q2-3rhw
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-434g-2637-qmqr
- Warn: Project is vulnerable to: GHSA-49q7-c7j4-3p7m
- Warn: Project is vulnerable to: GHSA-977x-g7h5-7qgw
- Warn: Project is vulnerable to: GHSA-f7q4-pwc6-w24p
- Warn: Project is vulnerable to: GHSA-fc9h-whq2-v747
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-76p3-8jx3-jpfq
- Warn: Project is vulnerable to: GHSA-3rfm-jhwj-7488
- Warn: Project is vulnerable to: GHSA-hhq3-ff78-jv3g
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-7fh5-64p2-3v2j
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-hc6q-2mpp-qw7j
- Warn: Project is vulnerable to: GHSA-4vvj-4cpr-p986
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
Score
2.9
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to form-capacitor
capacitor-heartland-form
Capacitor plugin for accepting payment through Heartland SDK
paystack-card-payment
A capacitor plugin form making debit card payment
capacitor-time-format-detector
Determine if system is using 24h or 12h time format
c3-cordova-to-capacitor
A tool to convert Cordova's config.json to Capacitor's capacitor.config.json format.