
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Formask is minimal form management abstract implemented by React. Provided with asynchronous validation, dynamic validation schema and work with native and third-party input field.
npm i formask --save
http://groupystinks.com/formask/
defaultValues
defines initial value of each field.
These initial values are stored in formask internal state and could be accessed through props.values
either in render props (render: (props: FormaskProps) => ReactElement
) or children if it's function (children: (props: FormaskProps) => ReactElement
).
defaultErrors
defines initial error of each field.
Initial errors are stored in formask internal state and can be accessed through
props.errors
like defaultValue does.
defaultTouches
defines initial touch of each field. Touch is stored in internal
state to track each field's user interaction status, where true
means already interacted. It can be accessed through props.touches
like defaultValue does.
redner
is a function to define Component will be rendered.
render
's first parameter is FormaskProps where all utility functions
and internal state are passed in.
onSubmit
is a function to be called while 'onsubmit' event is triggered. It will be passed in
form FormValues and FormaskProps.
schema
defines validation rule of each form field. There's some examples in Example.
Support Javascript native types including:
required
specify neccassary field. Formask will bypass field from validation if required is false.
customrule
is used as customized validation function. return true
means check pass, return false
means check failed.
errorMessages
defines corresponding error message to schema. If error occur, message will be exposed in props.errors
(see FormaskProps). It could be string, react element and whatever you may want when error occurs.
FormaskProps
is composed of internal state, methods and event handlers of Formask. It will be exposed in API like render
, onSubmit
and etc..
errors
specifies error message and valid status in each field.
values
specifies value in each field.
touches
specifies touch status in each field. Normally, touch is set to true
while user blur on input field.
For those fields have no input, please see Custom Touch Field.
types
specifies data type for each field if available. Formask will detect field data type from defaultValues, onChange event and etc..
isValid
specifies validation status on form.
isSubmitting
turn true
if form submit handler is triggered. Afterwards, setIsSubmitting is exposed to manipulate its status.
Event handlers of onsubmit event. Normally you would want to put it in form onsubmit attribute like:
<form onSubmit={submitHandler}>
...
Event handlers of onchange event. It will hook input value into Formask's values
.
Normally you would wnat to use it while your field component is native input like:
<input
id="first"
value={values.first}
onChange={changeHandler}
onBlur={blurHandler}
/>
Event handlers of onblur event. It will set Formask's touches
once user on blur input.
Like onChangeHanlder, we would like to use it in native input.
Get FormValues.
hook
serve as a bridge to connect Formask and Widget. Widget is any React element you want to record its
value into Formask's field. Under the hood, hook does few things you need to know:
Modify isSubmitting status.
passing nothing If no parameters is passed in, Formask reset all fields to clean state.
options.type:
reset
literally means to clear all changes. By definition, there's two types of reset you can set in options.type:
'clean'
to type, Formask will clean all internal state into empty, including values, errors and etc..'initial'
to type, Formask will reset to default values previously set by defaultValues, defaultErrors and etc..options.fields
If options.fields
is passed in, Formask will only reset specified fields according to what reset type is.
setTouches
manipulate Formask touches.
It let you can change touches on those non-input fields.
validate
will check fields value against schema and return result in promise. It support asynchronous validation. By default, if no parameters is passed, it will go through all fields. Optionally, you can pass in fields
to specify which to validate.
While submitHandler is triggered, validate
will be executed.
FAQs
Formask is minimal form management abstract implemented by React
We found that formask demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.