Giter Site home page Giter Site logo

formna / formna Goto Github PK

View Code? Open in Web Editor NEW
6.0 0.0 1.0 390 KB

Formna is a package which vanilla js developers can implement realtime form validation without much effort

Home Page: https://www.npmjs.com/package/formna

License: MIT License

JavaScript 84.83% HTML 15.17%
npm form javascript javascript-library

formna's Introduction

Formna

Quickly validate forms on your website


Formna is a fast, small, and easy to use JavaScript library. It makes the input and form validation super easy as validation logic can be changed according to users requirements.

Install

npm install formna

Usage

* To Validate a Single Input
  import { validateInput } from "formna";

  const inputId = "name"; // id of the input field
  const errorId = "nameError"; // id of the error field relevant to the input
  const initialValue = ""; // initial value
  const errorMessage = "Enter a valid name"; // error message to be show
  const errorClassName = "error"; // class related to changes to be shown in the input element when an error occurs
  const validator = (inputVal) => inputVal.trim().length > 0; // validation logic

  const {
    value: nameInputValue,
    isValid: isNameValid,
    focus: focusName,
    hasError: nameHasError,
    reset: resetName
  } = validateInput(inputId, errorId, initialValue, errorMessage, errorClassName, validator)
  • To Validate a Complete Form.
  import { validateForm } from "formna";

  const className = "form";
  const fileldDetails = [
    {
      id: "username", //id of the input field
      errorId: "usernameError", //id of the error field of the respective input
      initialValue: "", // initial value of the input
      errorMessage: "Enter a valid email", // error message to be shown
      errorClassName: "error", // class related to changes need to be seen in the input element
      validator: (inputVal) => inputVal.includes("@"), // validation logic
    },
    {
      id: "password",
      errorId: "passwordError",
      initialValue: "",
      errorMessage: "Enter a valid password",
      errorClassName: "error",
      validator: (inputVal) => inputVal.toString().trim().length > 6,
    },
  ];
  const postEndPoint = ""; // this is completely optional. you can see the same results without passing the third parameter.
  function formCallBack (data){ // This is also an optional parameter
    console.log(data)
  }
  validateForm(className, fileldDetails, postEndPoint, formCallBack);

Conclucsion

Using Formna you can implement real time form validation with side effects in your vanilla.js project.

formna's People

Contributors

shakyapeiris avatar iarchitsharma avatar

Stargazers

Sabuj Kundu avatar Cuzeac Florin avatar Nimsara Chamindu avatar Tudor Hulban avatar  avatar  avatar

Forkers

iarchitsharma

formna's Issues

Interesting, a roadmap?

I think you are trying to put nice work on the world. Seen AuthBee too.

What I liked from the Readme is that seems very easy to put your own strategies on the validator.

This said, I think something like an integration with rxjs to subscribe to the validation results or to the dom events could make it even more useful.

Have thought on a roadmap?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.