{"id":23269169,"url":"https://github.com/zdunecki/tenken-validator","last_synced_at":"2025-04-06T09:14:27.810Z","repository":{"id":217965313,"uuid":"65904319","full_name":"zdunecki/tenken-validator","owner":"zdunecki","description":"Validator for JS","archived":false,"fork":false,"pushed_at":"2016-08-21T21:17:22.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-12T14:30:50.909Z","etag":null,"topics":[],"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/zdunecki.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":"2016-08-17T12:04:54.000Z","updated_at":"2016-08-17T12:07:58.000Z","dependencies_parsed_at":null,"dependency_job_id":"cc39b9aa-91f6-4ca8-82bd-b194741e4787","html_url":"https://github.com/zdunecki/tenken-validator","commit_stats":null,"previous_names":["zdunecki/tenken-validator"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zdunecki%2Ftenken-validator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zdunecki%2Ftenken-validator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zdunecki%2Ftenken-validator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zdunecki%2Ftenken-validator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zdunecki","download_url":"https://codeload.github.com/zdunecki/tenken-validator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247457809,"owners_count":20941906,"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":[],"created_at":"2024-12-19T17:48:31.119Z","updated_at":"2025-04-06T09:14:27.781Z","avatar_url":"https://github.com/zdunecki.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tenken-validator\n\n#Validator for JS\n\n##Usage\n\n```javascript\nvar example = DOM.tenken();\n```\n###Events\n```javascript\nexample.on('submit',function(event,instance){\n //event - submit events\n //instance - tenken instance for validation.\n});\nexample.on('rules', @array of objects for rules); // make some rules with javascript\n```\n\n### Tenken instance\n#### Methods\n\n* **isValid**(validCallback,invalidCallback) - return **true** or **false** to check validation. **isValid callbacks** returns array of object for each valid/invalid response as first parametr\n  * validCallback(validResponse) - validResponse object:\n    * input - DOM element for correct validation\n    * valid - return **true**\n  * invalidCallback(invalidReponse) - invalidReponse object:\n    * input - DOM element for correct validation \n    * valid - return **false**\n    * message - return error message for each invalid validation\n    \n\n### Tenken HTML attributes\n#### validation attributes\n* **data-tenken-type** - pass one of tenken types:\n * email\n* **data-tenken-length** - pass range like \"5-20\"\n* **data-tenken-regex** - pass regex like \"^[A-Z][-a-zA-Z]+$\"\n\n#### invalid validation attributes\nPass some error message on invalid response.\n\nInvalid attributes are making by validation attributes and with **\"-error\"** ties like **data-tenken-length-error**.\n\n### Tenken JS rules\n#### build:\nJS rules are building like html attributes but without \"data-tenken\" string. **Note:** to create validation error message props use **{namespace}Error** syntax. \nSimple demo:\n```javascript\nexample.on('rules',[{length:\"5-20\",lengthError:\"Invalid length\"},{type:\"email\",typeError:\"wrong email\"}])\n.on('submit',onSubmit);\n```\n### exceptions\nException is **mixin** property. Mixins allows custom validation logic, for example:\n```javascript\nvar mixin = function(value){\n var foo = document.getElementById('foo').value;\n return value \u003e foo + 5; \n}\nexample.on('rules',[mixin:mixin,mixinError:'Value for this input must be 5 greater than foo value.'])\n.on('submit',onSubmit);\n```\n##Example\n### via HTML\n```html\n\u003cform id=\"form1\"\u003e\n \u003cinput type=\"text\" data-tenken-length=\"5-20\" data-tenken-length-error=\"Error! Min. length is 5 and max 20.\"/\u003e\n \u003cbutton type=\"submit\"\u003eSend\u003c/button\u003e\n\u003c/form\u003e\n```\n```javascript\nvar example = document.getElementById(\"form1\").tenken();\nexample.on('submit',function(event,instance){\n\n var valid = instance.isValid(function(valid){\n // some stuff with valid array of objects\n },function(invalid){\n // some stuff with invalid array of objects\n })\n if(!valid)\n  event.preventDefault(); // stop submitting form\n});\n```\n### via JS\n```html\n\u003cform id=\"form1\"\u003e\n \u003cinput type=\"text\"/\u003e\n \u003cbutton type=\"submit\"\u003eSend\u003c/button\u003e\n\u003c/form\u003e\n```\n```javascript\nvar example = document.getElementById(\"form1\").tenken();\nvar rules = [length:\"5-20\",lengthError:\"Error! Min. length is 5 and max 20.\"];\nexample.on('rules',rules).on('submit',function(event,instance){\n\n var valid = instance.isValid(function(valid){\n // some stuff with valid array of objects\n },function(invalid){\n // some stuff with invalid array of objects\n })\n if(!valid)\n  event.preventDefault(); // stop submitting form\n});)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzdunecki%2Ftenken-validator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzdunecki%2Ftenken-validator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzdunecki%2Ftenken-validator/lists"}