0.0.6 • Published 2 years ago

@osaze12/bootstrapped-form v0.0.6

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

Bootstrapped Form

Create a full form with validations, all with just 5 lines of code

Visit the project on Github (link is by your right hand side) to see image examples,

Getting started

Compatibility

Your project needs to use React 16.3 or later.

Installation

Add Bootstrapped Form to your project by executing

npm install @osaze12/bootstrapped-form or

yarn add @osaze12/bootstrapped-form.

Usage

Here's an example of basic usage:

import React, { useState } from "react";
import BootstrapForm from "@osaze12/bootstrapped-form";

// comes with stying
import "@osaze12/bootstrapped-form/dist/index.css";

function MyApp() {
  return (
    <div>
      <BootstrapedForm
        fields={{
          email: "email|required",
          password: "password|requiredvisibility",
          confirmPassword: "password|required|visibility",
          createAccount: "btn",
        }}
      />
    </div>
  );
}

Adding a select option & a checkbox using these code:

// comes with stying
import "@osaze12/bootstrapped-form/dist/index.css";
const genderList = [
  { name: "Male", value: "M" },
  { name: "Female", value: "F" },
];

function MyApp() {
  return (
    <div>
      <BootstrapedForm
        fields={{
          gender: `select|${JSON.stringify(genderList)}`,
          rememberMe: "checkbox",
          createAccount: "btn",
        }}
      />
    </div>
  );
}

And then to get the form data after successful validation, data will be passed to the payload prop, with 3 arguments, example below:

<BootstrapedForm
  payload={(data, isAccepted, notAccepted) => {
    // do what ever you want to do with the data here
  }}
  fields={{
    gender: `select|${JSON.stringify(f)}`,
    createAccount: "btn",
  }}
/>

You can also add an initial information to the form using the code below:

let genderList = [
    {name: "Male", value: "M"},
    {name: "Female", value: "M"}
]

<BootstrapedForm
  preloadData={{
    gender: "M",
  }}
  fields={{
    gender: `select|${JSON.stringify(genderList)}`,
    createAccount: "btn",
  }}
/>

User guide

Props

Prop nameDescription
fieldsThese is where you pass in your form title and values it should accept
preloadDatayou want to have initial data on the for, use case is: edit profile form
payloadreturn 3 args after form successfully pass validation:
1) the user form data
2) a success function, so data can be cleared
3) an error function, so data would not be cleared

Fields prop accepts the following:

NameDescription
input typeinput types includes, text, password, select, email, etc
requiredenables form to be checked for invalid data
visibilitythese adds text visibility and an eye icon to input field, use case is password
placeholderthese adds a placeholder to input fields
buttonadding a button or btn sting value, is read as a button

Preload prop accepts the following:

NameDescription
Titletitle of exisiting input field
Valuevalue to load into the field

Payload prop returns the following:

NameDescription
User datareturns the user form data after validation
Successa success function, so data can be cleared
Erroran error function, so data would not be cleared

License

ISC License.

Author

Agbi Osaze

osazeagbi@gmail.com

https://www.linkedin.com/in/osaze-agbi-b68328176/