1.0.27 • Published 3 years ago

form-panfilov v1.0.27

Weekly downloads
3
License
ISC
Repository
github
Last release
3 years ago

Description

React component that processes a form, its events and elements.

Installation

npm i --save form-panfilov

Testing

For testing, a bunch of jest and the testing library is used. To run the tests, type the following command

npm test

or command to restart the tests after they are changed

npm test:watch

Example and development

In the rollup folder in the terminal, enter the following command to create a link to the local npm package.

npm link

In the same folder, you need to create a link to react and react-dom.

Link to react

npm link ..\defaultReact\node_modules\react

Link to react-dom

npm link ..\defaultReact\node_modules\react-dom

After that, go to the defaultReact folder and run the project with the command

npm link start

Using

Key component of the form

<Form
    data={defaultValue}
    onSubmit={(fields: AuthUserFormInterface) => {
        if (!fields.email.error && !fields.password.error) {
            dispatch(
                authRequestFunc({
                  email: fields.email.value,
                  password: fields.password.value,
                  signal: abortController.signal,
                }),
            );
        }
    }}
    className={classNames('d-flex flex-direction-column', {
        disabled: authRequest,
    })}
>
other form elements
</Form>

Props:

  • data - an array of objects that contain information about the form fields. Form fields must match the interface AuthUserFormInterface.
interface AuthUserFormInterface {
    [key: string]: {
        defaultValue: string;
        defaultError: boolean;
    };
}
  • onSubmit - a callback function that handles sending a function to the backend;;
  • classname - writes custom classes for the form tag;
  • buttonText - writes custom text for the submit button;

Wrapper component for form fields

<FormWrapper errors={errors} form={defaultValue}>
    fields form
<FormWrapper/>

Props:

  • form - see the data props in the Form component described earlier;
  • errors - an array of objects that contains information about errors in form fields. The array element must conform to the ErrorMessages interface.
interface ErrorMessages {
    field: string;
    message: string[];
}

Text box component

<Input
    rules={{ requiredInputRules, emailRules }}
    placeholder="Email"
    type="text"
/>

Props:

  • type - input type;
  • classNames - writes custom classes for the input tag;
  • placeholder - placeholder for text field;
  • rules - validation rules for the text field. For validation, it is necessary to create an object of rules according to which the text field will be validated. At this point in time, text fields are validated using the following interface RulesValidationInterface;
  • name - the name of the text box;
  • defaultValue - default value;
  • errorMessage - field validation error message;

The fields classNames, name, defaultValue, errorMessage are optional.

1.0.27

3 years ago

1.0.26

3 years ago

1.0.25

3 years ago

1.0.24

3 years ago

1.0.23

3 years ago

1.0.22

3 years ago

1.0.21

3 years ago

1.0.19

3 years ago

1.0.18

3 years ago

1.0.17

3 years ago

1.0.16

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago