Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@kofile/react-form

Package Overview
Dependencies
Maintainers
24
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@kofile/react-form

A basic template for ES6 modules

  • 0.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
24
Weekly downloads
 
Created
Source

react-form

Usage

import React from 'react'
import Form from '@kofile/react-form'

class MyForm extends React.Component {
  genericValidate = v => v ? '' : 'error message'

  isPhoneNumber = v => { 
    /* some regex magic */
    return isNumber ? '' : 'error message'
  }

  handleSubmit = ({ formValues, formErrors, isValid }) => {
    if (!isValid) {
      return handleErrors(formErrors)
    }

    return handleSuccess(formValues)
  }

  render() {
    return (
      <div>
        <h2>My Awesome Form!</h2>
        <Form onSubmit={this.handleSubmit} validate={this.genericValidate} validateOn='onBlur'>
          <Form.Field id="name">
            {({ getInputProps, getLabelProps, getErrorProps }) => {
              const { value, id, ...props } = getInputProps()
              const { htmlFor, ...labelProps } = getLabelProps()
              const { error } = getErrorProps()

              return (
                <label htmlFor={htmlFor}>Your Name Is?</label>
                <input id={id} value={value} {...props} />
              )
            }}
          </Form.Field>
          <Form.Field id="age">
            {({ getInputProps, getLabelProps, getErrorProps }) => {
              const { value, id, ...props } = getInputProps()
              const { htmlFor, ...labelProps } = getLabelProps()
              const { error } = getErrorProps()

              return (
                <label htmlFor={htmlFor}>Your age Is?</label>
                <input id={id} value={value} type="number" {...props} />
              )
            }}
          </Form.Field>
          <Form.Field id="location">
            {({ getInputProps, getLabelProps, getErrorProps }) => {
              const { value, id, ...props } = getInputProps()
              const { htmlFor, ...labelProps } = getLabelProps()
              const { error } = getErrorProps()

              return (
                <label htmlFor={htmlFor}>Your location Is?</label>
                <textarea id={id} value={value} {...props} />
              )
            }}
          </Form.Field>
        </Form>
      </div>
    )
  }
}

FAQs

Package last updated on 13 Sep 2017

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc