Socket
Socket
Sign inDemoInstall

@surinderlohat/lohat-from-validation

Package Overview
Dependencies
3
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @surinderlohat/lohat-from-validation

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


Version published
Maintainers
1
Created

Readme

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

Last updated on 26 Aug 2021

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc