{"id":19838282,"url":"https://github.com/barisates/react-valid-form","last_synced_at":"2025-05-01T18:31:08.576Z","repository":{"id":35128699,"uuid":"209386062","full_name":"barisates/react-valid-form","owner":"barisates","description":"React form validation component.","archived":false,"fork":false,"pushed_at":"2023-02-27T15:39:01.000Z","size":4704,"stargazers_count":8,"open_issues_count":13,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-26T12:48:20.317Z","etag":null,"topics":["form","form-validation","form-validation-react","form-validator","input-validation","react","react-component","reactjs","validation","validator"],"latest_commit_sha":null,"homepage":"https://barisates.github.io/react-valid-form/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/barisates.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-09-18T19:16:16.000Z","updated_at":"2023-03-07T05:13:03.000Z","dependencies_parsed_at":"2023-02-15T09:45:44.305Z","dependency_job_id":null,"html_url":"https://github.com/barisates/react-valid-form","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barisates%2Freact-valid-form","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barisates%2Freact-valid-form/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barisates%2Freact-valid-form/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barisates%2Freact-valid-form/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/barisates","download_url":"https://codeload.github.com/barisates/react-valid-form/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224269984,"owners_count":17283649,"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-validation","form-validation-react","form-validator","input-validation","react","react-component","reactjs","validation","validator"],"created_at":"2024-11-12T12:17:14.655Z","updated_at":"2024-11-12T12:17:15.408Z","avatar_url":"https://github.com/barisates.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-valid-form\nReact form validation component.\n\n[![npm package][npm-image]][npm-url]\n[![Build Status][travis-image]][travis-url]\n[![Dependencies Status][david-image]][david-url]\n[![Package Size][bundlephobia-image]][bundlephobia-url]\n\n## Getting started\n\n#### Install with NPM:\n\n```\n$ npm install react-valid-form-component\n```\n\n#### Usage\n\n**Live Demo [CodeSandbox](https://codesandbox.io/s/react-valid-form-9fkx7 \"CodeSandbox\")**\n\nWith this component, you can validate form fields according to the rules you specify. Simply define your form in the ```\u003cValidForm\u003e\u003c/ValidForm\u003e``` tags to validate.\n\nComponent supports standard form elements;\n```html\n\u003cinput /\u003e\n\u003cselect\u003e\u003c/select\u003e\n\u003ctextarea\u003e\u003c/textarea\u003e\n```\n\n##### Example\n\nWhen the form is validated, it is automatically posted. You can manually Submit or Fetch using ```nosubmit``` prop.\nYou can follow the details about the form with ```onSubmit={(form, data, valid)}``` event.\n\n\u003e Auto Submit Example [CodeSandbox](https://codesandbox.io/s/auto-submit-example-9zdpi \"CodeSandbox\")\n\n```jsx\n// App.js\nimport React from 'react';\nimport ValidForm from 'react-valid-form-component'\n\nfunction App() {\n    return (\n        \u003cValidForm action=\"https://httpbin.org/post\" method=\"post\"\u003e\n            \u003cdiv\u003e\n                \u003clabel for=\"validation\"\u003eText Example: \u003c/label\u003e\n                \u003cinput\n                    type=\"text\"\n                    name=\"validation\"\n                    id=\"validation\"\n                    /* validation rules */\n                    required\n                    minLength=\"3\"\n                    maxLength=\"50\"\n                /\u003e\n            \u003c/div\u003e\n            \u003cdiv\u003e\n                \u003clabel for=\"validation\"\u003eEmail Example: \u003c/label\u003e\n                \u003cinput\n                    type=\"email\" /* validation with type */\n                    name=\"validation\"\n                    id=\"validation\"\n                /\u003e\n            \u003c/div\u003e\n            \u003cbutton type=\"submit\"\u003eSend Form\u003c/button\u003e\n        \u003c/ValidForm\u003e\n    )\n}\nexport default App;\n```\n\n##### Manual Fetch Example\n\nOnce the form is validated, you can send the data manually.\n\n\u003e Fetch Example [CodeSandbox](https://codesandbox.io/s/fetch-example-4kqoy \"CodeSandbox\")\n\n```jsx\n// App.js\nimport React from 'react';\nimport ValidForm from 'react-valid-form-component'\n\nfunction App() {\n    const onSubmit = (form, data, valid) =\u003e {\n        const requestOptions = {\n            method: \"POST\",\n            headers: {\n                Accept: \"application/json\",\n                \"Content-Type\": \"application/json\"\n            },\n            body: JSON.stringify(data)\n        };\n\n        fetch(\"https://httpbin.org/post\", requestOptions)\n            .then(response =\u003e {\n                if (response.ok) {\n                    return response.json();\n                } else {\n                    throw new Error(`Response Error, Status Code : ${response.status}`);\n                }\n            })\n            .then(json =\u003e {\n                console.log(json);\n            })\n            .catch(function (error) {\n                console.error(error);\n            });\n    }\n    return (\n        \u003cValidForm nosubmit onSubmit={(form, data, valid) =\u003e onSubmit(form, data, valid)}\u003e\n            \u003cdiv\u003e\n                \u003clabel for=\"validation\"\u003eText Example: \u003c/label\u003e\n                \u003cinput\n                    type=\"text\"\n                    name=\"validation\"\n                    id=\"validation\"\n                    /* validation rules */\n                    required\n                    minLength=\"3\"\n                    maxLength=\"50\"\n                /\u003e\n            \u003c/div\u003e\n            \u003cdiv\u003e\n                \u003clabel for=\"validation\"\u003eEmail Example: \u003c/label\u003e\n                \u003cinput\n                    type=\"email\" /* validation with type */\n                    name=\"validation\"\n                    id=\"validation\"\n                /\u003e\n            \u003c/div\u003e\n            \u003cbutton type=\"submit\"\u003eSend Form\u003c/button\u003e\n        \u003c/ValidForm\u003e\n    )\n}\nexport default App;\n```\n##### Props\n\n```nosubmit``` Disable auto submit.\n\n```novalid``` \"onSubmit\" event is also triggered when the form is not valid.\n\n```data``` Default form elements value.\n\n##### Events\n```onSubmit={(form, data, valid)}``` When the form is submitted, it is triggered.\n\n- ```form``` : Html form elemet.\n\n- ```data``` : Form fields data.\n\n- ```valid``` : Form is valid? (true/false)\n\n##### Default Validation Rules\n\nYou can add rules and change warning texts. You can use rules by defining them as ```type=\"\"``` or ```prop```. Follow the document for details.\n\n- ```required=\"true\"``` : Required field. \n\n- ```number=\"true\"``` : Only number field. Can be used as **Type**.\n\n- ```alphanumeric=\"true\"``` : Only alphanumeric character.\n\n- ```letters=\"true\"``` : Only letters.\n\n- ```min=\"integer\"``` : Min value limitations.\n\n- ```max=\"integer\"``` :  Max value limitations.\n\n- ```minlength=\"integer\"``` : Min value length limitations.\n\n- ```maxlength=\"integer\"``` : Max value length limitations.\n\n- ```email=\"true\"``` : Only email field. Can be used as **Type**.\n\n- ```url=\"true\"``` : Only url field. Can be used as **Type**.\n\n- ```confirm=\"Confirmation Field ID\"``` : Verifies that the two fields have the same value. Such as the \"Password Repeat\" field.\n\n- ```regexp=\"Regular Expression\"```\n\n##### Add Validation Rule\n\nImport ```Rules``` and ```Warnings``` objects for add rule.\n\n```jsx\nimport ValidForm, { Rules, Warnings } from 'react-valid-form';\n\n// rule\nRules.customRule = (value) =\u003e {\n  return (value === \"Custom Rule\")\n};\n\n// warning alert\nWarnings.customRule = (params) =\u003e `This field is custom rule ${params}.`\n\n// using\n\u003cinput type=\"text\" name=\"validation\" id=\"validation\" customRule /\u003e\n```\n##### React Select\nTo use required validation with [react-select](https://github.com/jedwatson/react-select \"react-select\") component.\n\n```jsx\n\u003cSelect\n  name=\"reactSelect\"\n  inputId=\"reactSelect\"\n  className=\"react-select-valid\"\n  options={[\n    { label: 'Option 1', value: '1' },\n    { label: 'Option 2', value: '2' },\n    { label: 'Option 3', value: '3' },\n  ]}\n/\u003e\n```\n- Add **react-select-valid** to the component as **className** for validation.\n- Fill in the component's **inputID** and **name** property.\n\n- If you don't want to validate, set the **inputId** property to **no-validation**.\n\n------------\n#### Author\n\n**Barış Ateş**\n - http://barisates.com\n - [github/barisates](https://github.com/barisates \"github/barisates\")\n\n[npm-image]:https://img.shields.io/npm/v/react-valid-form-component.svg\n[npm-url]:https://www.npmjs.com/package/react-valid-form-component\n[travis-image]:https://travis-ci.org/barisates/react-valid-form.svg?branch=master\n[travis-url]:https://travis-ci.org/barisates/react-valid-form\n[david-image]:https://david-dm.org/barisates/react-valid-form.svg\n[david-url]:https://david-dm.org/barisates/react-valid-form\n[bundlephobia-image]:https://badgen.net/bundlephobia/minzip/react-valid-form-component\n[bundlephobia-url]:https://bundlephobia.com/result?p=react-valid-form-component","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbarisates%2Freact-valid-form","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbarisates%2Freact-valid-form","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbarisates%2Freact-valid-form/lists"}