{"id":21524865,"url":"https://github.com/degjs/formvalidation-required","last_synced_at":"2025-03-17T18:17:49.590Z","repository":{"id":14367157,"uuid":"76422664","full_name":"DEGJS/formValidation-required","owner":"DEGJS","description":"A required field rule for the DEGJS formValidation module.","archived":false,"fork":false,"pushed_at":"2023-01-03T15:17:15.000Z","size":1344,"stargazers_count":0,"open_issues_count":11,"forks_count":0,"subscribers_count":10,"default_branch":"main","last_synced_at":"2025-03-07T08:01:47.040Z","etag":null,"topics":["forms"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/DEGJS.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}},"created_at":"2016-12-14T03:48:42.000Z","updated_at":"2021-01-25T21:28:58.000Z","dependencies_parsed_at":"2023-01-13T17:54:42.992Z","dependency_job_id":null,"html_url":"https://github.com/DEGJS/formValidation-required","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DEGJS%2FformValidation-required","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DEGJS%2FformValidation-required/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DEGJS%2FformValidation-required/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DEGJS%2FformValidation-required/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DEGJS","download_url":"https://codeload.github.com/DEGJS/formValidation-required/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244085010,"owners_count":20395523,"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":["forms"],"created_at":"2024-11-24T01:30:07.511Z","updated_at":"2025-03-17T18:17:49.572Z","avatar_url":"https://github.com/DEGJS.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# formValidation-required\n![Run Tests](https://github.com/DEGJS/formValidation-required/workflows/Run%20Tests/badge.svg)\n\nA required field rule module for the DEGJS [formValidation](https://github.com/DEGJS/formValidation) module.\n\n\n## Install\nformValidation-required is an ES6 module. Consequently, you'll need an ES6 transpiler ([Babel](https://babeljs.io) is a nice one) as part of your Javascript workflow.\n\nIf you're already using NPM for your project, you can install formValidation-required with the following command:\n\n```\n$ npm install @degjs/form-validation-required\n```\n\n\n## Usage\nAfter importing, formValidation rule modules can be instantiated by passing an array of names into a formValidation options object:\n\n```js\nimport formValidation from \"@degjs/form-validation\";\n\n/* Import the Required rule module */\nimport required from \"@degjs/form-validation-required\";\n\nconst validationOptions = {\n    rules: [\n        required\n    ]\n};\n\n/* Instantiate the formValidation module on an element */\nconst formElement = document.querySelector('.form');\nconst validationInst = formValidation(formElement, validationOptions);\n```\n\nOptionally, default rule settings can be overridden by instantiating the rule as a function and passing options as an object: \n```js\nconst validationOptions = {\n    rules: [\n        required({\n        \tmessage: 'This message will override the default rule message.',\n            events: [\n                'focusout',\n                'submit'\n            ]\n        })\n    ]\n};\n```\n\nformValidation-required builds upon the HTML5 `required` validation pattern. Therefore, after instantiating the rule module, a field in the validation instance will be tested by this rule simply by adding a `required` attribute to the field input.\n\nThis rule module contains its own default validation message. However, this message can be overridden by adding a data attribute at the field or form level (in that order of importance).\n\nSample Markup:\n```html\n\u003cform class=\"form\" data-validation-required-message=\"This message will override the default rule message.\"\u003e\n    \u003cfieldset\u003e\n        \u003cdiv class=\"js-validation-field\" data-validation-required-message=\"This message will override both the default rule message and the form element message.\"\u003e\n            \u003clabel for=\"firstname\"\u003eFirst Name\u003c/label\u003e\n            \u003cinput type=\"text\" required id=\"firstname\" name=\"firstname\"\u003e\n        \u003c/div\u003e\n        \u003cbutton type=\"submit\"\u003eSubmit\u003c/button\u003e\n    \u003c/fieldset\u003e\n\u003c/form\u003e\n```\n\n\n## Options\n\n#### options.message\nType: `String`  \nDefault: `This field is required.`  \nThe default message displayed when a field fails this rule's validation test.\n\n#### options.messageAttr\nType: `String`  \nDefault: `data-validation-required-message`  \nThe data attribute formValidation will check when determining [message hierarchy](https://github.com/DEGJS/formValidation#configuring-error-messages)\n\n#### options.events\nType: `Array`  \nDefault: `['focusout','submit']`  \nAn array of DOM events that will cause the rule to run validation on a field (or the entire form, when using `submit`). NOTE: `focusout` should be used in place of `blur` due to event bubbling limitations.\n\nFor more detailed usage instructions, see the [formValidation Usage](https://github.com/DEGJS/formValidation#usage) documentation.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdegjs%2Fformvalidation-required","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdegjs%2Fformvalidation-required","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdegjs%2Fformvalidation-required/lists"}