1.4.25 • Published 3 years ago

formalization v1.4.25

Weekly downloads
2
License
BSD-3-Clause
Repository
github
Last release
3 years ago

formalization

NPM JavaScript Style Guide Build Status npm Support

A simple and straight-foward wrapper around forms that works as you would expect. Fully customizable and able to handle files and images, using formdata.

Install

npm install --save formalization

Usage

import * as React from 'react';

import { Form, Input, Group, Text, When, Value } from 'formalization';

export default function App () {
	const onSubmit = (data) => {
		//handle data
	};

	const validateEmail = (value) => {
		if (/*validation fails*/) {
			return "Email not valid";
		}
	}

    return (
		<Form onSubmit={onSubmit}>
			<Group name="user">
				<Input name="email" validates={validateEmail} />
				<div className="error-message">
					<Error name="email" />
				</div>

				<Input name="name" />
			</Group>

			<Toggle name="newsletter" />

			<When name="newsletter">
				Thank you for signing our newsletter <Value pathname="user.name" />
			</When>

			<Text name="message" />
		</Form>
    );
}

Components

Form

The core component of the form, this handles, gathers and set the data. If you return false from the onChange/onSubmit, it will clear the form, if you return any data, it will adjust the form accordling, if you return null, nothing happens.

props

namerequirementtypedescription
dataoptionalObject, function (newValue)A useState array that will be used to interact with an outer object, don't switch between using a controlled state data and uncontrolled
initialDataoptionalObjectInitial state of the form data
fileoptionalbooleanChanges the result of the onChange/onSubmit to a FormData
onChangeoptionalfunction (data)Function that returns the data when the form is updated
onSubmitrequiredfunction (data)Function that returns the data when the form is submitted
onErroroptionalfunction (data)Function that returns errors messages given
validateOnChangeoptionalbooleanEnable callback calls and updates on change, instead of submit

Group

Group component allow you to nest data inside of objects

props

namerequirementtypedescription
namerequiredstringThe key that this object will be recognized inside of the form result

Error

Displays error messages from the component linked

props

namerequirementtypedescription
namerequiredstringThe name that this component will print errors from

Input | Text | File | Select | Toggle

The form input that handles each type in a specific way, since toggle has some "peculiarities", we handle him separatedly from the input.

props

namerequirementtypedescription
namerequiredstringThe key that this object will be recognized inside of the form result
onChangeoptionalfunction (data, htmlnode)Callback that let's you know when this component has changed value
filtersoptionalArray<function (data) => any>An array that can modify the value before it's handled to the form itself

Wrapper

In case you are using another package or you want to build a component that interacts with the form, you can use the wrapper for this. You can use the filters prop to alter the value cleanly.

props

namerequirementtypedescription
namerequiredstringThe key that this object will be recognized inside of the form result
valuerequiredanyThe value that will be inserted into the form
setValuerequiredfunction (newValue)This is required so formalization can set the data innerly
filtersoptionalArray<function (data) => any>An array that can modify the value before it's handled to the form itself

Value

You can use this component to display a value from inside of the form without having too much issue about it. You need to use name or pathname.

props

namerequirementtypedescription
nameoptionalstringThe name of the key relative to the position in the form
pathnameoptionalstringThe absolute path to the key and it's name
defaultoptionalanyDefault value to be displayed in case there is a null value
filtersoptionalArray<function (data) => any>An array that can modify the value before it's handled to the form itself

When

This component allows you to conditionally display it's children based on the condition given. You need to use name or pathname.

props

namerequirementtypedescription
nameoptionalstringThe name of the key relative to the position in the form
pathnameoptionalstringThe absolute path to the key and it's name
whenrequiredboolean or function (value) => booleanThe condition that prevents the children from appearing

License

BSD-3 © aposoftworks

1.4.25

3 years ago

1.4.24

4 years ago

1.4.22

4 years ago

1.4.21

4 years ago

1.4.23

4 years ago

1.4.20

4 years ago

1.4.17

4 years ago

1.4.19

4 years ago

1.4.18

4 years ago

1.4.16

4 years ago

1.4.15

4 years ago

1.4.14

4 years ago

1.4.13

4 years ago

1.4.12

4 years ago

1.4.11

4 years ago

1.4.10

4 years ago

1.4.9

4 years ago

1.4.8

4 years ago

1.4.7

4 years ago

1.4.6

4 years ago

1.4.5

4 years ago

1.4.4

4 years ago

1.4.3

4 years ago

1.4.2

4 years ago

1.4.1

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.2.7

4 years ago

1.2.6

4 years ago

1.2.4

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.0

4 years ago

1.2.1

4 years ago

1.1.9

4 years ago

1.1.8

4 years ago

1.1.7

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago