Adrenalin Media - React Form Validation Component
A React form validation wrapper and templating component. It supports all base html field types (input, textarea, select, radio, checkbox) and includes a few base validation rules for standard validations such as email, password, digits etc.
It includes support for adding custom validators via a defined validator object structure as well as the ability to overide the default field template component at either the parent ReactForm or child ReactFormField level.
- Useage
- Installation
- Getting Started
- Javascript
- SCSS
- Props
- Default Validators
- Custom Validators
- Field Template Component
- Developing
- Publishing
This component uses NPM to install and manage versioning.
As this is a private npm package, authentication is first required.
```
npm loginUsername: adrenalin
Password: *
Email: info@adrenalinmedia.com.au
Then install the module -
``
yarn add @adrenalin/react-form
or
``
npm install @adrenalin/react-form
The module exposes 2 main components, the parent ReactForm and the child ReactFormField fields.
ReactForm represents the form wrapper and will return a
#### Use for all ReactFormField fields
`js
onSuccess={this.handleFormValidated.bind(this)}
onError={this.handleFormError.bind(this)}
fieldComponent={MyCustomFieldTemplate}
>
`#### Use for a specific ReactFormField field
`js
type="text"
name="firstName"
id="firstname"
label="First Name First"
placeholder="First Name"
required={true}
validators={["name"]}
errorMessages={{
required: "Please enter your first name."
}}
fieldComponent={MyCustomFieldTemplate}
/>
`#### Available
fieldComponent propsAll props applied to
ReactFormField will be passed down to the template component provided. In addition a number of special props are added to assist with building out the template logic.---
####
inputElement : elementThe input element itself (input, textarea, select), this will let you decide where to render the element inside your template.
`
// template componentreturn(
;
{/input element/}
{props.inputElement}
)
`---
####
classes : objectAn object of conditional state classes detailing the current validation and interaction state of the input -
`js
classes: {
hasValue: "";
inheritedClasses: "";
isDisabled: "";
isFocused: "";
isIncomplete: "is-incomplete";
isInvalid: "";
isValid: "";
}
`---
####
errors : arrayAn array error message for the corresponding current validation errors
`js
errors: ["This field is required.", "Please enter some digits."];
`---
####
showErrors : booleanA boolean detailing where to visually show errors for this field. Returned on bluring of an field input or when the form action is submitted.
---
####
valid : booleanA boolean representing if the input is completly valid and will submit.
---
####
passwordToggleBtn : elementThe prebound password toggle button. Only passed for
type="password" inputs.Developing
JS files for this module are found in the root
src folder. The entry point can be found at src/index.js. The module also includes base styles inside the scss/ folder.To preview and test the module whilst developing there is also an included test react project under
test-app. This app is generated from create react app and is not included in the outputted npm package.Publishing
After making changes, a commit should be created and, if required, merged back into the
develop branch. The version number should then be incremented using one of the npm version commands outlined below. This will ensure that a new commit is created and tagged with the new version number.npm version patch - Minor bug fixes/changesnpm version minor - For new backwards compatible featuresnpm version major - For any backwards incompatible changesFinally, publish your changes to NPM using
npm publish. This will also push all changes and tags to the develop branch on origin`.