0.1.67 • Published 3 years ago

ez-formikui v0.1.67

Weekly downloads
2
License
MIT
Repository
github
Last release
3 years ago

EZ-FormikUI

Easy form generator using Formik, MaterialUI, Google Recaptcha and Axios.

An easy way to generate forms using json like objects.

npm.io

Links

Installation

npm:

npm install ez-formikui

yarn:

yarn add ez-formikui

Usage

import EZFormikUI from "ez-formikui";

const Example = () => {
  return (
    <EZFormikUI
      fields={
        {
          fieldName: "email",
          label: "Email Address",
          type: "text",
          options: "email",
          props: { disabled: true },
          initialValue: ""
        },
        {
          fieldName: "password",
          label: "Password",
          type: "text",
          options: "password",
          initialValue: ""
        }
      }
      title="EZ-FormikUI"
      paragraph="Easy form generator"
      onSubmit={values => alert(JSON.stringify(values, undefined, 4))}
      validate={values => {
        const errors = {};

        if (values.custom > 2) {
          errors.custom = "No more then 2!";
        }

        return errors;
      }}
    />
  );
};

Examples

JS Example
TS Example
Edit EZ-FormikUI example

Config

General config that the form uses.

const config = {
  captchaKey: "",
  text: {
    checkCaptcha: "Check the box!",
    submit: "Submit",
    selectEmpty: "None",
    addNewItem: (name: string) => `Add new ${name}`,
  },
};

export default config;

captchaKey

If you want to use captcha in your forms register to get captcha key and set up you're key

text

Default text that the form will use. here you can change it.

Config Setup

To change the config import the setCaptchaKey, changeText from the package.

Example:

import React from "react";
import { setCaptchaKey, changeText } from "ez-formikui";

const captchaKey = "<You're captcha key>";
const textObj = {
    checkCaptcha: "Check the box!",
    submit: "Submit",
    selectEmpty: "Clear Selection",
    addNewItem: (name: string) => `Add new ${name} to the array.`,
};

setCaptchaKey(captchaKey);
changeText(textObj);

export default function App() {
  return (
    ...
  );
};

Props

NameTypeRequiredDefaultDescription
fieldsFieldType[](array):heavy_check_mark:an array of fields to be generated in the form.
titlestring:x:adds title to the form.
paragraphstring:x:adds paragraph to the form.
validationSchemayup validation schema:x:validates your form with yup schema
validatefunc:x:a function to validate your form signature: (values: object) => object
onSubmitfunc | string:heavy_check_mark:a function / url to submit your form if string is provided the values will be submitted to the given url (default request method is post, can be changed with submitMethod prop).if function is provided then the function will be called upon submit (the function will be wrapped automatically in try catch block to handle errors) signature: (values: object, actions: FormikHelpers) => void
submitMethodget | delete | put | patch | post:x:postHTTP request method to send the form data (only works if the onSubmit prop is a string)
afterDefaultSubmitfunc:x:a function to execute after default submit (only executed if onSubmit prop is a string). signature: (res: AxiosResponse, actions: FormikHelpers) => void
useCaptchaboolean:x:falseif set to true the form will use google recpatcha v2 (note that to use this feature you will need to set up captcha key)
gridPropsobject:x:{ alignItems: "center", direction: "row", justify: "space-between",spacing: 1,}MaterialUI Grid props to be applied to the fields div container
submitPropsobject:x:{grid:{xs:12}}props to apply on the submit button

Fields

The fields of the form. Checkout the examples.

Array

Prop NameTypeRequiredDefaultDescription
typestring:heavy_check_mark:the type of the field needs to be "array" in this case
fieldNamestring:heavy_check_mark:the name of the field note that it needs to be unique and cannot be "fieldName" (causes a bug)
labelstring:heavy_check_mark:the label of the field.
initialValuearray:heavy_check_mark:the initialValue of the field.
ofFieldType[](array):heavy_check_mark:the fields that will render on each row of the array note that nested arrays is not supported
maxnumber:x:if provided the array will have max length.
startEmptyboolean:x:falseif true the array will starts as an empty array.
newItemTextstring:x:the text that will render on the add new item button.this will override the default text
rowPropsobject:x:extra props to pass to the row (style, className, etc...)
propsobject:x:extra props to pass to the component (style, className, etc...)
gridobject:x:{ xs:12 }Grid Sizes object

Autocomplete

Prop NameTypeRequiredDefaultDescription
typestring:heavy_check_mark:the type of the field needs to be "autocomplete" in this case
fieldNamestring:heavy_check_mark:the name of the field note that it needs to be unique and cannot be "fieldName" (causes a bug)
labelstring:heavy_check_mark:the label of the field.
optionsarray:heavy_check_mark:the options of the component needs to be array of { value: any; label: string }
initialValueany:heavy_check_mark:the initialValue of the field.
propsobject:x:extra props to pass to the component (style, className, etc...)
gridobject:x:{ xs:12 }Grid Sizes object

Checkbox

Prop NameTypeRequiredDefaultDescription
typestring:heavy_check_mark:the type of the field needs to be "checkbox" in this case
fieldNamestring:heavy_check_mark:the name of the field note that it needs to be unique and cannot be "fieldName" (causes a bug)
labelstring:heavy_check_mark:the label of the field.
optionsarray:heavy_check_mark:the options of the component needs to be array of { value: any; label: string }
initialValuestring[]:heavy_check_mark:the initialValue of the field.
propsobject:x:extra props to pass to the component (style, className, etc...)
gridobject:x:{ xs:12 }Grid Sizes object

Dates

Date pickers (date, time or date and time).

Prop NameTypeRequiredDefaultDescription
typestring:heavy_check_mark:the type of the field needs to be on of "date" \| "time" \| "datetime" in this case
fieldNamestring:heavy_check_mark:the name of the field note that it needs to be unique and cannot be "fieldName" (causes a bug)
labelstring:heavy_check_mark:the label of the field.
initialValueMomentInput:x:Date.now()the initialValue of the field.
propsobject:x:extra props to pass to the component (style, className, etc...)
gridobject:x:{ xs:12 }Grid Sizes object

Other

Create your own component.

Prop NameTypeRequiredDefaultDescription
typestring:heavy_check_mark:the type of the field needs to be "other" in this case
fieldNamestring:heavy_check_mark:the name of the field note that it needs to be unique and cannot be "fieldName" (causes a bug)
labelstring:heavy_check_mark:the label of the field.
componentComponent:heavy_check_mark:an React component that will receive those props
initialValueany:heavy_check_mark:the initialValue of the field.
propsobject:x:extra props to pass to the component (style, className, etc...)
gridobject:x:{ xs:12 }Grid Sizes object

Radio

Prop NameTypeRequiredDefaultDescription
typestring:heavy_check_mark:the type of the field needs to be "radio" in this case
fieldNamestring:heavy_check_mark:the name of the field note that it needs to be unique and cannot be "fieldName" (causes a bug)
labelstring:heavy_check_mark:the label of the field.
optionsarray:heavy_check_mark:the options of the component needs to be array of { value: any; label: string }
initialValuestring:heavy_check_mark:the initialValue of the field.
propsobject:x:extra props to pass to the component (style, className, etc...)
gridobject:x:{ xs:12 }Grid Sizes object

Select

Prop NameTypeRequiredDefaultDescription
typestring:heavy_check_mark:the type of the field needs to be "select" in this case
fieldNamestring:heavy_check_mark:the name of the field note that it needs to be unique and cannot be "fieldName" (causes a bug)
labelstring:heavy_check_mark:the label of the field.
optionsarray:heavy_check_mark:the options of the component needs to be array of { value: any; label: string }
initialValueany:heavy_check_mark:the initialValue of the field.
isMultiboolean:x:falseif set to true the multiple options could be selected.in this case the initialValue suppose to be array
propsobject:x:extra props to pass to the component (style, className, etc...)
gridobject:x:{ xs:12 }Grid Sizes object

Switch

Prop NameTypeRequiredDefaultDescription
typestring:heavy_check_mark:the type of the field needs to be "switch" in this case
fieldNamestring:heavy_check_mark:the name of the field note that it needs to be unique and cannot be "fieldName" (causes a bug)
labelstring:heavy_check_mark:the label of the field.
initialValueboolean:heavy_check_mark:the initialValue of the field.
propsobject:x:extra props to pass to the component (style, className, etc...)
gridobject:x:{ xs:12 }Grid Sizes object

Textarea

Prop NameTypeRequiredDefaultDescription
typestring:heavy_check_mark:the type of the field needs to be "textarea" in this case
fieldNamestring:heavy_check_mark:the name of the field note that it needs to be unique and cannot be "fieldName" (causes a bug)
labelstring:heavy_check_mark:the label of the field.
rowsnumber:heavy_check_mark:the number of initial rows the textarea will have.
rowsMaxnumber:x:999the number of max rows.
initialValuestring:heavy_check_mark:the initialValue of the field.
propsobject:x:extra props to pass to the component (style, className, etc...)
gridobject:x:{ xs:12 }Grid Sizes object

TextField

Prop NameTypeRequiredDefaultDescription
typestring:heavy_check_mark:the type of the field needs to be "text" in this case
fieldNamestring:heavy_check_mark:the name of the field note that it needs to be unique and cannot be "fieldName" (causes a bug)
labelstring:heavy_check_mark:the label of the field.
options"email" | "password" | "number" | "tel" | "text":heavy_check_mark:the type of the input.
initialValuestringnumberDate:heavy_check_mark:the initialValue of the field.
propsobject:x:extra props to pass to the component (style, className, etc...)
gridobject:x:{ xs:12 }Grid Sizes object

License

MIT

0.1.67

3 years ago

0.1.66

3 years ago

0.1.65

4 years ago

0.1.64

4 years ago

0.1.63

4 years ago

0.1.62

4 years ago

0.1.61

4 years ago

0.1.6

4 years ago

0.1.52

4 years ago

0.1.51

4 years ago

0.1.5

4 years ago

0.1.41

4 years ago

0.1.42

4 years ago

0.1.43

4 years ago

0.1.44

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago