
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.
react-superform
Advanced tools
Form with superpowers for ReactJS
Tired of writing validation yourself? Tired of implementing custom elements for inputs when you already know HTML5 forms? React Superform to the rescue!
npm i -S react-superform
React Superform lets you create validatable <form>
with HTML5 form elements regardless of HTML5 validation support. Create your component and extend Superform
class instead of React.Component
use inherited methods to make your form awesome and user friendly!
import Superform from "react-superform";
class MyForm extends Superform {
onSuccessSubmit(data) {
console.log(data);
}
onErrorSubmit(errors, data) {}
render() {
return (
<form noValidate onSubmit={ this.handleSubmit.bind(this) }>
<input
type="email" // validate email
ref="email" // ref is required to read the attributes
name="email" // name field
value={ this.getValueOf("email") }
onChange={ this.handleChange.bind(this) }
required // field is required
/>
<p className="error">{ this.getErrorMessageOf("email") }</p>
<input type="submit" />
</form>
);
}
}
ReactDOM.render(<MyForm />, document.getElementById("root"));
That's it, you are ready to go!
You can also check examples
dir.
max
maxLength
min
minLength
pattern
required
type="email"
type="number"
type="url"
data-equals="<other field name>"
check whether field is the same as other field.
Warning: Avoid deep circular equality check. A -> B -> A
will end up with exception but A -> B -> C -> A
can freeze the tab.
data-messages="<custom messages>"
allows to define custom messages. It accepts JSON object with keys corresponding to failed rules.
Superform's Superclass
Kind: global class
Promise
Promise
Promise
boolean
string
| boolean
| undefined
Object
Object
Object
Array
boolean
boolean
string
Called on form success submission.
Kind: instance method of Superform
Param | Type | Description |
---|---|---|
data | Object | Form data with all fields valid |
Called on form failure submission.
Kind: instance method of Superform
Param | Type | Description |
---|---|---|
errors | Object | Form errors object |
data | Object | Form data |
Promise
Handler for input change called internally.
Kind: instance method of Superform
Returns: Promise
- Promise resolved when data and errors are set if any
Param |
---|
event |
Promise
Handler for form submission. Your form should call it as onSubmit
handler.
Kind: instance method of Superform
Returns: Promise
- Promise resolved with onSuccessSubmit
or onErrorSubmit
result
Param |
---|
event |
Promise
Marks form as submitted by setting this.status.submitted
to true
.
Kind: instance method of Superform
Returns: Promise
- Promise resolved after state is set.
boolean
Determines whether form was submitted.
Kind: instance method of Superform
string
| boolean
| undefined
Returns value of specified field.
Kind: instance method of Superform
Returns: string
| boolean
| undefined
- Field value
Param | Type | Description |
---|---|---|
name | string | Field name |
Object
Links field value with form state. Simulates two way data binding.
Kind: instance method of Superform
Param | Type | Description |
---|---|---|
name | string | Field name |
Object
Returns form data.
Kind: instance method of Superform
Returns: Object
- Form data which is this.state.data
Object
Returns form errors.
Kind: instance method of Superform
Returns: Object
- Form data which is this.state.errors
Array
Returns errors of specified field.
Kind: instance method of Superform
Param | Type | Description |
---|---|---|
name | string | Field name |
boolean
Determines whether form is valid or not based on form errors.
Kind: instance method of Superform
boolean
Determines whether field is valid or not based on form errors.
Kind: instance method of Superform
Param | Type | Description |
---|---|---|
name | string | Field name |
string
Returns final error message for particular field
Kind: instance method of Superform
Returns: string
- Error message for the field
Param | Type | Description |
---|---|---|
name | string | Field name |
FAQs
Form with superpowers for ReactJS
We found that react-superform 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.