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

formkit

Package Overview
Dependencies
Maintainers
1
Versions
374
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

formkit

Smart framework agnostic form helper.

  • 1.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
841
increased by69.22%
Maintainers
1
Weekly downloads
 
Created
Source

formkit

Build Status npm version dependencies dependencies

Smart form helper. It's framework agnostic.

Install

npm install formkit

Usage

There is example of common usage without any frameworks.

import formkit from 'formkit';

const validate = (errors, values) => {
  if (!values.firstname) errors.firstname = 'Required';
};

// get new form instance
const form = formkit.newForm();
// initialize form fields
form.init([
  'firstname',
], validate);

const submitHandler = (values) => console.log('The form has submittes with', values);
form.onSubmit(submitHandler);

// change field's value
form.fields.firstname.handleChange('my new name');

console.log(form.fields.firstname.dirty)        // false - field is different with previously saved state
console.log(form.fields.firstname.touched)      // true - field was dirty at least once since form has initialized.
console.log(form.fields.firstname.valid)        // true
console.log(form.fields.firstname.invalidMsg)   // '' - message which sets in validate function

// emit submit event - "submitHandler" will be called
form.handleSubmit();

To use in your favorite framework you have to call field's handleChange method after each field changes. And call fom.handleSubmit() submit on form submit if submitting is using. In other hand you can add handler on form saving form.onSave(callback) to save form's state after field change.

Test running

npm test

FAQs

Package last updated on 10 Jul 2019

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