{"id":18895164,"url":"https://github.com/coffezilla/react-bhx-form","last_synced_at":"2025-04-15T01:13:44.481Z","repository":{"id":236564225,"uuid":"402282001","full_name":"coffezilla/react-bhx-form","owner":"coffezilla","description":"Simple form with validation in ReactJS and Typescript - create-react-app","archived":false,"fork":false,"pushed_at":"2021-12-14T21:56:52.000Z","size":550,"stargazers_count":6,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-15T01:13:39.685Z","etag":null,"topics":["form","form-react","form-validation","javascript","reactjs","submit-form","typescript","validation-form"],"latest_commit_sha":null,"homepage":"https://react-bhx-form.netlify.app","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/coffezilla.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-09-02T03:52:06.000Z","updated_at":"2024-03-03T09:54:19.000Z","dependencies_parsed_at":"2024-04-27T20:38:22.370Z","dependency_job_id":null,"html_url":"https://github.com/coffezilla/react-bhx-form","commit_stats":null,"previous_names":["coffezilla/react-bhx-form"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coffezilla%2Freact-bhx-form","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coffezilla%2Freact-bhx-form/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coffezilla%2Freact-bhx-form/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coffezilla%2Freact-bhx-form/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/coffezilla","download_url":"https://codeload.github.com/coffezilla/react-bhx-form/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248986315,"owners_count":21194025,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["form","form-react","form-validation","javascript","reactjs","submit-form","typescript","validation-form"],"created_at":"2024-11-08T08:26:53.625Z","updated_at":"2025-04-15T01:13:44.465Z","avatar_url":"https://github.com/coffezilla.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-bhx-form\n\nThis form is a very useful project for all kinds of usage in ReactJS projects. Was made using create-react-app and Typescript for a better implementation.\n\n## Feat\n\n- Typescript\n- ReactJS ( sample was made using create-react-app )\n\n## How to use\n\nTo use this form, put the component folder (FormValidation) inside your project component's folder.\n\nNow, you can import a function for validation and the interface (typescript) to deal with useEffects type.\n\n```tsx\nimport { useState } from 'react';\nimport { validateForm, IForm } from './components/FormValidation';\n```\n\n```tsx\nconst [formFields, setFormFields] = useState\u003cIForm['inputs']\u003e([\n\t{\n\t\tname: 'name',\n\t\tvalue: '',\n\t\terror: '',\n\t\ttype: 'text',\n\t\tisRequired: true,\n\t},\n]);\n```\n\n```tsx\n// validation of the form\nconst validationForm = () =\u003e {\n\tconst inputRequired = validateForm(formFields, setFormFields);\n\tconst hasNoErrors = inputRequired.hasPassed;\n\n\treturn hasNoErrors;\n};\n\n// generic handle for inputs\nconst handleChange = (e: any) =\u003e {\n\tconst isCheckBox = e.target.type === 'checkbox';\n\tlet currentValue = e.target.value;\n\n\t// OPTIONAL: clean spaces\n\tif (\n\t\te.target.name === 'nickname' ||\n\t\te.target.name === 'password' ||\n\t\te.target.name === 'passwordConfirm' ||\n\t\te.target.name === 'phone'\n\t) {\n\t\tcurrentValue = currentValue.replace(/\\s/g, '');\n\t\tcurrentValue = currentValue.toLowerCase();\n\t}\n\n\tsetFormFields(\n\t\tformFields.map((field: any) =\u003e {\n\t\t\tif (field.name === e.target.name) {\n\t\t\t\treturn {\n\t\t\t\t\t...field,\n\t\t\t\t\tvalue: isCheckBox ? e.target.checked : currentValue,\n\t\t\t\t\terror: '',\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn { ...field };\n\t\t}),\n\t);\n};\n\n// submit handle\n// if isValid so you can submit the form\nconst handleSubmit = (e: any) =\u003e {\n\te.preventDefault();\n\tconst isValid = validationForm();\n\n\tif (isValid) {\n\t\t// use async function for server validation\n\t\talert('SUBMITED!!!');\n\t}\n};\n```\n\nSet your html\n\n```tsx\n\u003cform onSubmit={handleSubmit}\u003e\n\t\u003clabel htmlFor={formFields[0].name}\u003e\n\t\tName:\n\t\t\u003cinput\n\t\t\ttype={formFields[0].type}\n\t\t\tname={formFields[0].name}\n\t\t\tid={formFields[0].name}\n\t\t\tmaxLength={formFields[0].maxLength}\n\t\t\tvalue={formFields[0].value}\n\t\t\tonChange={handleChange}\n\t\t/\u003e\n\t\t\u003cspan\u003e{formFields[0].error}\u003c/span\u003e\n\t\u003c/label\u003e\n\t\u003cbutton type=\"submit\"\u003eSubmit Form\u003c/button\u003e\n\u003c/form\u003e\n```\n\nIn order to make everything work properly you have to set your input following the index number used in your useState.\n\n## Error message\n\n```html\n\u003cspan\u003e{formFields[0].error}\u003c/span\u003e\n```\n\n## Inside view - @types\n\n```tsx\ntype inputTypes =\n\t| 'text'\n\t| 'select'\n\t| 'radio'\n\t| 'checkbox'\n\t| 'textarea'\n\t| 'email'\n\t| 'password'\n\t| 'tel';\n\ninterface IInput {\n\tname: string;\n\tvalue: string;\n\terror: string;\n\ttype: inputTypes;\n\tmaxLength?: number;\n\tminLength?: number;\n\tisEqual?: boolean | string;\n\tisRequired?: boolean;\n}\n\nexport interface IForm {\n\tinputs: IInput[];\n}\n```\n\n## View\n\n![form.gif](react-bhx-form%2081e845e634d146d3ba332816dca6720d/form.gif)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoffezilla%2Freact-bhx-form","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoffezilla%2Freact-bhx-form","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoffezilla%2Freact-bhx-form/lists"}