An open API service indexing awesome lists of open source software.

https://github.com/yazaabed/react-form-validations

Created with CodeSandbox
https://github.com/yazaabed/react-form-validations

Last synced: 3 months ago
JSON representation

Created with CodeSandbox

Awesome Lists containing this project

README

        

# react-form-validations
Created with CodeSandbox

---

Hey, my name is Yazan,

I am searching for advice after I watch "React Advanced Pattern" Course. I got an idea to build a form with inputs without the need to handle all event for your form element.

for example this is `` with validation rules and this is the message shown

```

This field is required

```

You can create your custom validation like this:
```
customeFormValidation = (id, value, rule) => {
switch (rule.code) {
case "custome-1":
return false;

default:
console.warn("Missing validation for: ", rule);
}

return false;
};

{
if (!this.form.validator.validate()) {
} else {
console.log(this.form.validator.data);
}
}}
validator={this.form.validator}
customeFormValidation={this.customeFormValidation}
>

```

I am wondering if this idea good enough to continue work within React?
I am thinking to change this to work with `React.createContext.` more flexible than the solution I add.

*Note: The code is really bad! But I was learning how things work with React*