0.3.0 • Published 6 years ago

reformact v0.3.0

Weekly downloads
6
License
MIT
Repository
github
Last release
6 years ago

Reformact

A react form component that uses state. built with react for react with <3

Getting Started

These instructions will help you use this package, alright, let's get down to business.

installing

Run this command in a terminal to install with npm: npm i reformact -S

Usage

import reformact in your application as follows: import Form from 'reformact';

Reformact gets an array of fields and render them based on them type; for example a minimal login form would be like:

class LoginForm extends Component {
  submit = (values) => {
    const {username, password} = values //
    this.props.apiLogin(username, password)
  }
  render() {
    return (<Form fields={[
        {
          type: "text", //  html input type
          name: "username", //  unique name for input
          placeholder: "Jon doe", // placeholder
          required: true
        }, {
          type: "password",
          name: "password",
          placeholder: "****",
          required: true
        }]
     } onSubmit={(values) => this.submit(values)} submitText='Login'/>)
  }
}

this will generate a form with two inputs named username and password and a submit button as shown below.

reformact

this Form has an onSubmit attribute that gets fired when the form is submitted either with click or enter/return key and gets field values.

the submitText is the title of submit button.

Supported field types

Currently reformact supports text, number, password, textarea, select, checkbox and radio inputs, but will support lots of inputs soon.

Field attributes

The following table showing attributes. Field type * means all types field.

AttributesField typevaluedescription
required*boolean(default=false)check if field has a value if set true.
requiredPhrase*string(default=This field is required.)error shown when field is required and empty.
name*stringa unique string in form, on submitting the form you can access a field value by values.<name>
placeholder*string(default=null)inputs placeholder.
defaultValue*any(default=null)in case of editing forms pass current values via defaultValue.
maxLengthtext, number and passwordnumber(default=null)maximum value length.
maxLengthErrorPhrasetext, number and passwordstring(default=This field accepts <maxLength> characters.)error shown when maxLength is crossed.
multiSelectselectboolean(default=false)set true if select can have more than one values.
selectHandleselectcomponent(default=an ungly css-made triangle), example: <i className="ion-ios-arrow-down (which needs ionicons)this option is for changing the select box handle component.
optionsselect, radioarray of objects with label and valuechoices for select input and radio group.
checkboxLabelcheckboxstring(default:'')checkbox label.
mustBeCheckedPhrasecheckboxstring(default:'This field must be checked.')error shown when checkbox is required and not checked.

License

This project is licensed under the MIT License.

0.3.0

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.0

6 years ago

0.0.15

6 years ago

0.0.14

6 years ago

0.0.13

6 years ago

0.0.12

6 years ago

0.0.11

6 years ago

0.0.10

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago