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

formelio

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

formelio

Forms for humans

  • 0.2.0
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

logo

Forms for human beings

NPM JavaScript Style Guide

Installation

To use Formelio from a React component, just install it with your favorite package manager (like NPM):

npm install --save formelio

Usage

Once installed, you'll be able to import and use it from your Javascript/Typescript code. Here's a simple example of a simple login form, without validation or password hiding (please, don't do this in production 😜):

import React, { useState } from 'react';
import { Form } from 'formelio';
import 'formelio/dist/index.css';

export const MyForm = () => {
  const [value, onChange] = useState({});
  const fields = [{ name: 'email' }, { name: 'password' }];
  return <Form {...{ fields, value, onChange }} />;
};

Go to https://sgmonda.com/formelio/ to see this and other usage examples working.

Form properties

A form requires the following main properties:

PropertyRequiredDescriptionDefault
fieldsyesForm inputs to include in the form-
onChangeyesChange event handler, receiving form value and validity status-
valueyesCurrent value for all (or some) inputs{}
delaynoTime to wait before triggering onChange() after an input change500ms
colorsnoSimple customization{ accent: '#5196D5', error: '#D65947' }

Fields

It is a list (Array) of field definitions. A field definition is a plain object where field properties are defined. Example:

<Form
  ...
  fields={[
    { name: 'firstName', type: 'text', required: true },
    { name: 'age', type: 'number' },
  ]}
  ...
/>
PropertyRequiredDescriptionDefault
nameyesField name-
labelnoField label for humans. If not provided, name is used-
requirednoIf the a value is mandatoryfalse
typenoInput type: "text", "text-multiline", "number", "date", "select", "tags", "check", "password""text"
sizenoPercentage of row width to be used as field width, in range [0, 1]1
iconnoIcon to be shown (from fontawesome)-
validatornoFunction that validates provided value-
whennoList of conditions to show/hide the field-

For complex fields (those with fields inside), there are additional properties:

PropertyRequiredDescriptionDefault
lengthnoFunction to compute the amount of items in the list() => 0
fieldsnoSubfields list[]

Take a look at examples page to see all this in action.

onChange()

It is a change event handler, that will be called when the form is modified. It also receives a validation state, according with required properties and custom validators (see next section). Example:

<Form
  ...
  onChange={ (value, isValid) => { /* Do whatever you want */ } }
  ...
/>

Contributing

Git hooks

This project uses git hooks for:

Storybook

To play with individual components and see usage cases, you can run Storybook as follows:

$ npm run storybook

Development

Clone this repository and run the following:

$ npm i

Then open 3 terminals:

  • Terminal 1: Open dev server, to compile and bundle everything on every change:

    $ npm run dev
    
  • Terminal 2: Open test watcher, to run tests on every change:

    $ npm run dev:test
    
  • Terminal 3: Serve (watching) the example

    $ npm run dev:site
    

To prevent Invalid hook call error during development of another app using formelio as file dependency, I mean:

// path/to/myOtherProject/package.json

"dependencies": {
  "formelio": "path/to/formelio",
}

We should link react version from formelio project. Example:

$ npm link path/to/myOtherProject/node_modules/react-dom
$ cd path/to/myOtherProject/ && npm i

Deployment

To publish on npm:

$ npm publish

To update gh pages:

$ npm run site:deploy

License

Feel free to use this project as you need, always under the terms of MIT license.

FAQs

Package last updated on 08 Jul 2021

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