Socket
Book a DemoInstallSign in
Socket

@surinderlohat/lohat-from-validation

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

@surinderlohat/lohat-from-validation

Lohat Form validation is a tool for easy form validations based on the react hooks and reactive programing.

0.1.4
unpublished
latest
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Lohat Form validation

Lohat Form validation is a tool for easy form validations based on the react hooks and reactive programing.

Installation

npm install @surinderlohat/lohat-from-validation
yarn add @surinderlohat/lohat-from-validation

Form Helping Methods

Note: all methods are available like: form.onSubmit()

MethodPARAMSRETURN VALUE
onSubmitNoReturn from values and error state
errorMessagesNoDisplay all errors from the fields
resetToDefaultNoReset form state to default All fields will be reset to the default state
getFieldfieldKeyused to get the specific field from the form

Field Methods

Note: we can get any specific field using form.getField('userName') --all methods are available like: form.getField('userName').hasChanges

MethodTYPERETURN VALUE
hasChangesGetterReturn field state i.e it's changed or not
hasErrorGetterReturn error state of the specific field
errorMessageGetterReturn error message for current field
setValueFunctionSet value of specific field

How to use

import { FieldObject, useLohatForm } from '@surinderlohat/lohat-from-validation';
const field: FieldObject = {
  userName: {
    label: 'UserName',
    value: '123',
    rules: {
      required: true,
      regExp: /^[0-9]+$/,
      min: 2,
      max: 10,
    },
  },
  email: {
    label: 'Email',
    value: 'abc@gmail.com',
  },
};

function FormValidation() {
  const form = useLohatForm(field);
  return (
    <div className="App">
      <form>
        <FormField field={form.getField('userName')} />
        <FormField field={form.getField('email')} />
      </form>
    </div>
  );
}

function FormField({ field }: Props) {
  return (
    <div>
      <label>{field.label}</label>
      <input {...field.bind()}></input>
      <p> errorMessage{'' + field.errorMessage}</p>
    </div>
  );
}

https://codesandbox.io/embed/sleepy-napier-ci2lg

License

MIT Free Software!

FAQs

Package last updated on 26 Aug 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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.