Formydable

is a form validator library that is delightfully made in react. It is so light with unique setting and cognitive design. the rules are eloquent which will make the schema so powerful yet easy to understand, and implement on any kind of components. unlike any other form validator library, formydable is complex that allows you to bend and shape it on almost what ever you want. furthermore, formydable is capable on working both controllable and uncontrollable form fields and to know more just read the documentation below.

Installation #

npm i formydable
Imports #

import { useForm, useFormSupplier, FormSupplier, Validator, DoneTypingEvent } from "formydable"
Getting Started #

This is a react form validator that is delightfully made by mytabowrks which is blazingly fast and can be easily use and implement in any field components with ease.

Tip

Rules validation order is from left to right. it will validate firstly the one on the left side which is the most priority. commonly required rule.

Controllable Fields #

you can make controllable fields without a sweat. just add a single line and you are done.

Customize Messages #

you can make your own static rule messages by using "failedIn" without affecting the rules messages model.

✔️ Looks Good!

Remember setting a schema only works once and will never change again after, because that is how react useState works. but if you want to update constantly the schema or the default value like when you are updating information, you can unmount the component(which you put the useForm) after submit then mount it again when you are about to update information...

Submitting Form #

form only exist to submit that is why it is not complete without submitting it on server side.

Remember setting a schema only works once and will never change again after, because that is how react useState works. but if you want to update constantly the schema or the default value like when you are updating information, you can unmount the component(which you put the useForm) after submit then mount it again when you are about to update information...

The fields which are not registered from the schema are excluded from FormEvent method json, param and paramArray.

If you want to involve the unregistered field. You can always use FormEvent method formData that will return FormData instance.

Advance Design Pattern #

We use FormSupplier to provide formState, formUpdate and formRegistry to children components, and we use useFormSupplier to get FormSupplier provided to children components

✔️ Looks good!
✔️ Looks good!
✔️ Looks good!
✔️ Looks good!
Aliased Registry #

It is inevitable that some form fields are multiple with the same name on it, the problem is we wanted to add those new or other fields into form state registry. for that reason formydable use alias registry and make a counter measure about those stuffs.

✔️ Looks good!
FormUpdate With DoneTypingEvent #

It is use to fire the event after user is done typing, that will save a lot of unessesary execution of state changes while typing.

Looks good!
✔️ Looks good!
Aliased Rule Parameters #

developer`s perspective is different with user`s. that is why you can always use aliases (@) to make user`s apprehend the messages

✔️ Looks good!
✔️ Looks good!
Customize Rules #

you can make your own rules.

✔️ Looks good!
Tip

Registering customize rules is once and for all.

Updating Rules Messages #

if you don`t like the default rules messages you can always do this to change it permanently.

✔️ Looks good!
✔️ Looks good!

API

Rules #

NameHow to useDescriptionMessage
requiredrequiredit will require the form field to be filledThe :attribute field is required
emailemailit will validate if the field contain a valid e-mailThe :attribute field must be valid email
minmin:<number>it will validate the minumum character, number, checkbox is checked, select(multiple) is selected, file(multiple) is selected.e.g. min:10The :attribute field must be atleast :min (character, items, files)
maxmax:<number>it will validate the maximum character, number, checkbox is checked, select(multiple) is selected, file(multiple) is selected.e.g. max:20The :attribute field may not be greater than :max (character, items, files)
mimesmimes:<files mimes>it will validate the specific mimes of the files which are allowed.e.g. mimes:jpg,pdf,rarThe :attribute only allows :mimes
alphaalphait will validate if the field value is only contain letterThe :attribute may only contain letters
alpha_spacealpha_spaceit will validate if the field only contain letters with spacesThe :attribute must contain alphabet with spaces
alpha_numalpha_numit will validate if the field contain letters with numbersThe :attribute may only contain letters and numbers.
alpha_slugalpha_slugit will validate if the field contain letters, numbers, and underscoreThe :attribute may only contain letters, numbers, and underscore.
alpha_dashalpha_dashit will validate if the field contain letters with numbers and dashesThe :attribute may only contain letters, numbers, and dashes.
urlurlit will validate if the field contain valid urlThe :attribute must be a valid url.
max_sizemax_size:<number>it will validate if the field contain a maximum file size and the size must calculate in kilobytes.e.g. max_size:5000The :attribute may not be greater :max_size kilobytes.
min_sizemin_size:<number>it will validate if the field contain a minimum file size and the size must calculate in kilobytes.e.g. min_size:1000The :attribute must be atleast :min_size kilobytes.
required_ifrequired_if:<field_id>=<expected_value>it will require the field, if the target field matches the expected value. you can use exact value or regular expression likerequired_if:bio=.+. .+ means has any value.e.g. required_if:country=AU since most of the time field ids are not the same as the labels and same with the values label. that is why you can use Aliasing(@)e.g. required_if:country@Country=AU@AustraliaThe :attribute field is required when :required_if is :value.
samesame:<field_id>it will validate the field until the target field contain the same value.e.g. same:pass since most of the time field ids are not the same as the labels. you can use Aliasing(@)e.g. same:pass@PasswordThe :attribute and :same must match.
useForm #

it is use to register schema and to get formState, formUpdate, formSubmit, formRegistry.

Property
Property
Type
Type
Default
Default
Description
Description
const {
} = useForm(
)
FormSupplier #

it is use to set the useForm functions into useFormSupplier which you can use under FormSupplier as a wrapper.

Property
Property
Type
Type
Default
Default
Description
Description
useFormSupplier #

it is use to fetch FormSupplier provided.

Property
Property
Type
Type
Default
Default
Description
Description
const {
} = useFormSupplier()
DoneTypingEvent #

it is use to fire the event after user done typing, that will save a lot of unessesary execution while typing.

Property
Property
Type
Type
Default
Default
Description
Description
DoneTypingEvent(
delaynumber700it is the miliseconds aloted for users typing, if its exceeded on aloted time then it will know that the user stops typing.
)

Validator

Validator.rulesExtend #

it is use to make your own rules.

Property
Property
Type
Type
Default
Default
Description
Description
Validator.rulesExtend({
})
Validator.rulesUpdateMessage #

it is use to change the message of the existing rules.

Property
Property
Type
Type
Default
Default
Description
Description
Validator.rulesUpdateMessage({
ruleName,string-the name of the rule you want to update the message
})
Warning!

In this pre-deployed stage, most of the library you will witness has yet been publish or update in npm.