2.0.0 • Published 3 years ago

easy-react-form-component v2.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

Easy React Form Component

npm package dl/week last commit

An easy-to-use React Component to create form with simple validation quickly.

Installation

To install the stable version:

Using npm as your package manager.

  npm install --save easy-react-form-component

Using yarn as your package manager.

  yarn add easy-react-form-component

Documentation

Props

NameTypeDescription
fieldsArray of ObjectArray of object containing all your fields details.
classNameStringString to use your own classes.
styleObjectObject to use Style on the form element ( use like any style props ).
onSubmitCallBack functionFunction called when the form is submitted receiving an object with property name corresponding to your field names.
onErrorCallBack functionFunction called when an error is triggered on submit

Field

Property nameTypeDescriptionDefault
nameStringThe name your input will have and the property name in the object you'll receive onSubmit. This property is MANDATORY.
typeStringType of your field.text
labelObjectAn Object containing the properties : "class", "style", "value". The value is what will be displayed as the label text{}
verifObjectAn Object with the verification to do on the Field and the error message to display.{}
resetOnChangeBooleanReset or not this field errors when onChange event is triggered.false
resetOnInputBooleanReset or not this field errors when onInput event is triggered.false
resetOnClickBooleanReset or not this field errors when onClick event is triggered.false
resetOnDoubleClickBooleanReset or not this field errors when onDoubleCLick event is triggered.false
resetOnFocusBooleanReset or not this field errors when onFocus event is triggered.false
resetOnKeyDownBooleanReset or not this field errors when onKeyDown event is triggered.false
resetOnMouseEnterBooleanReset or not this field errors when onMouseEnter event is triggered.false
resetOnMouseLeaveBooleanReset or not this field errors when onMouseLeave event is triggered.false
optionsArray of ObjectAvailable only for select type Field. Array of Object containing all your options details.

Options

Property nameTypeDescriptionDefault
textStringThe displayed text for the option .copy of value or Empty String
valueStringThe return valued when submitting the form.copy of text or Empty String
selectedBooleanWhether the Option must be the selected one at the init of the form.false
disabledBooleanWhether the Option must be selectable or not.false

Verif

The value of a property in verif must be an object containing the properties "value" which is what is described in the table under and "message" if you want to set an error message (this must be JSX).

Available verification

Property nameDescription
requiredA Boolean which, if true, indicates that the input must have a value before the form can be submitted.
maxLengthThe maximum length of the value to accept for this input.
minLengthThe minimum length of the value to accept for this input.
maxThe maximum value to accept for this input.
minThe minimum value to accept for this input.
patternThe regex pattern for the input.
validateYou can pass a callback function as the argument to validateYou can pass a callback function as the argument to validate.
valueAsNumberReturns a Number normally. If something goes wrong NaN will be returned.
valueAsDateReturns a Date normally. If something goes wrong null will be returned.
setValueAsReturn input value by running through the function.

Implemented Types

  • select
  • button
  • checkbox
  • color
  • date
  • datetime-local
  • email
  • file
  • image
  • month
  • number
  • password
  • radio
  • range
  • reset
  • search
  • submit
  • tel
  • text
  • time
  • url
  • week

Implemented Properties

  • className (available on select too)
  • value (available on select too)
  • defaultValue (available on select too)
  • style (available on select too)
  • autoCapitalize
  • autoComplete
  • color
  • checked
  • defaultChecked
  • dir
  • disabled
  • step
  • placeholder

Implemented Events

  • onClick
  • onInput
  • onChange
  • onDoubleClick
  • onKeyDown
  • onMouseEnter
  • onMouseLeave

Examples

Simple form with Submit

import EasyForm from "easy-react-form-component"

function App() {
    return (
        <EasyForm
            fields={[
                // Text field
                {
                    type:"text",
                    name:"example",
                    label: {
                        value: "Example field"
                    }
                },


                // Select field
                {
                    type:"select",
                    name:"selectExample",
                    label : {
                        value: "Example Select"
                    },

                    // Options
                    options: [
                        {
                            text: "Nice Option",
                            value: "nice"
                        },
                        {
                            text: "Not Nice option",
                            value: "notNice",
                            selected: true
                        }
                    ]
                },


                // Submit button
                {
                    type:"submit",
                    name:"submitInput",
                    value:"Submit"
                }
            ]}
            onSubmit={(e) => console.log("My values are: ", e)} />
    );
};

export default App;
2.0.0

3 years ago

1.2.5

3 years ago

1.3.2

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.4

3 years ago

1.2.3

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.0

3 years ago