npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-superform

v0.2.1

Published

Form with superpowers for ReactJS

Downloads

16

Readme

react-superform

Build Status

react-superform

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!

Installation

npm i -S react-superform

Getting Started

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"));

Working example

That's it, you are ready to go!

Examples

You can also check examples dir.

Available HTML5 validation methods

  • max
  • maxLength
  • min
  • minLength
  • pattern
  • required
  • type="email"
  • type="number"
  • type="url"

Available custom validation methods

Equality

data-equals="<other field name>" check whether field is the same as other field.

Example

Warning: Avoid deep circular equality check. A -> B -> A will end up with exception but A -> B -> C -> A can freeze the tab.

Custom messages

data-messages="<custom messages>" allows to define custom messages. It accepts JSON object with keys corresponding to failed rules.

Example

Contributors

Superform

Superform's Superclass

Kind: global class

superform.onSuccessSubmit(data)

Called on form success submission.

Kind: instance method of Superform

| Param | Type | Description | | --- | --- | --- | | data | Object | Form data with all fields valid |

superform.onErrorSubmit(errors, data)

Called on form failure submission.

Kind: instance method of Superform

| Param | Type | Description | | --- | --- | --- | | errors | Object | Form errors object | | data | Object | Form data |

superform.handleChange(event) ⇒ 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 |

superform.handleSubmit(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 |

superform.markAsSubmitted() ⇒ 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.

superform.isSubmited() ⇒ boolean

Determines whether form was submitted.

Kind: instance method of Superform

superform.getValueOf(name) ⇒ 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 |

superform.linkStateOf(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 |

superform.getData() ⇒ Object

Returns form data.

Kind: instance method of Superform
Returns: Object - Form data which is this.state.data

superform.getErrors() ⇒ Object

Returns form errors.

Kind: instance method of Superform
Returns: Object - Form data which is this.state.errors

superform.getErrorsOf(name) ⇒ Array

Returns errors of specified field.

Kind: instance method of Superform

| Param | Type | Description | | --- | --- | --- | | name | string | Field name |

superform.isFormValid() ⇒ boolean

Determines whether form is valid or not based on form errors.

Kind: instance method of Superform

superform.isFieldValid(name) ⇒ boolean

Determines whether field is valid or not based on form errors.

Kind: instance method of Superform

| Param | Type | Description | | --- | --- | --- | | name | string | Field name |

superform.getErrorMessageOf(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 |