From 6cd4f954ae193acc379f7e979b2ef67ecc81c809 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ionic=C4=83=20Biz=C4=83u?= Date: Wed, 25 May 2016 14:48:05 +0300 Subject: [PATCH] Updated docs --- CONTRIBUTING.md | 4 ++- DOCUMENTATION.md | 63 ++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 26 ++++++++++++-------- 3 files changed, 82 insertions(+), 11 deletions(-) create mode 100644 DOCUMENTATION.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7c9f03c..254ff4c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -59,6 +59,8 @@ Contributions are more than welcome! Thanks! :sweat_smile: + + [1]: https://github.com/IonicaBizau/validate5/issues -[2]: https://github.com/IonicaBizau/code-style \ No newline at end of file +[2]: https://github.com/IonicaBizau/code-style diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md new file mode 100644 index 0000000..320baf5 --- /dev/null +++ b/DOCUMENTATION.md @@ -0,0 +1,63 @@ +## Documentation + +You can see below the API reference of this module. + +### `validate5(forms)` +Handles the submit event on the selected forms. + +You may want to extend the `validate5.patterns` object with custom types. By default it has validation for: + + - `email`: `[emailRegex, "Invalid email address"]` + +e.g. `validate5.patterns.myCustomType = [/^[0-9]+$/g, "Not a number."]` + +Use the `validate5.skips` array to handle elements that should be skipped when validating. By default it skips the `type=submit` inputs. + +e.g. + +```js +validate5.skips.push(function (c) { + if (c.getattribute("data-ignore-validation")) { return true; } +}); +``` + +#### Params +- **String** `forms`: The form(s) selector you want to automagically validate on submit. + +### `validateInput(input)` +Validates an input element. + +#### Params +- **HTMLElement** `input`: The input to validate. + +#### Return +- **Validify** The [`validify`](https://github.com/IonicaBizau/validify) result. + +### `inputs(formElm, cb)` +Iterate the inputs in the provided form. + +#### Params +- **HTMLElement** `formElm`: The form element. +- **Function** `cb`: The callback function. + +#### Return +- **Array** The array of inputs. + +### `validateForm(formElm)` +Validates the form element. + +#### Params +- **HTMLElement** `formElm`: The form element. + +#### Return +- **Array** An array of errors. + +### `showErrors(formElm)` +Validates the form and displays the errors. + +#### Params +- **HTMLElement** `formElm`: The `
` element to validate. + +#### Return +- **Array|Boolean** An array of errors or `false` if all the fields are valid. + diff --git a/README.md b/README.md index 7b6df4a..cb12ff4 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,14 @@ -# validate5 [![PayPal](https://img.shields.io/badge/%24-paypal-f39c12.svg)][paypal-donations] [![Version](https://img.shields.io/npm/v/validate5.svg)](https://www.npmjs.com/package/validate5) [![Downloads](https://img.shields.io/npm/dt/validate5.svg)](https://www.npmjs.com/package/validate5) [![Get help on Codementor](https://cdn.codementor.io/badges/get_help_github.svg)](https://www.codementor.io/johnnyb?utm_source=github&utm_medium=button&utm_term=johnnyb&utm_campaign=github) + +# validate5 + + [![PayPal](https://img.shields.io/badge/%24-paypal-f39c12.svg)][paypal-donations] [![AMA](https://img.shields.io/badge/ask%20me-anything-1abc9c.svg)](https://github.com/IonicaBizau/ama) [![Version](https://img.shields.io/npm/v/validate5.svg)](https://www.npmjs.com/package/validate5) [![Downloads](https://img.shields.io/npm/dt/validate5.svg)](https://www.npmjs.com/package/validate5) [![Get help on Codementor](https://cdn.codementor.io/badges/get_help_github.svg)](https://www.codementor.io/johnnyb?utm_source=github&utm_medium=button&utm_term=johnnyb&utm_campaign=github) > Form validations made easy. [![validate5](http://i.imgur.com/tLbLEeJ.png)](http://ionicabizau.github.io/validate5/example) ## :cloud: Installation - + Check out the [`dist`](/dist) directory to download the needed files and include them on your page. @@ -15,10 +18,10 @@ If you're using this module in a CommonJS environment, you can install it from ` $ npm i --save validate5 ``` - + ## :clipboard: Example - + ```js /** @@ -43,9 +46,10 @@ $ npm i --save validate5 // To validate the forms on submit, use: validate5("form"); ``` - + ## :memo: Documentation - + + ### `validate5(forms)` Handles the submit event on the selected forms. @@ -105,18 +109,20 @@ Validates the form and displays the errors. #### Return - **Array|Boolean** An array of errors or `false` if all the fields are valid. - + + ## :yum: How to contribute Have an idea? Found a bug? See [how to contribute][contributing]. + ## :scroll: License - + [MIT][license] © [Ionică Bizău][website] - + [paypal-donations]: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=RVXDDLKKLQRJW [donate-now]: http://i.imgur.com/6cMbHOC.png [license]: http://showalicense.com/?fullname=Ionic%C4%83%20Biz%C4%83u%20%3Cbizauionica%40gmail.com%3E%20(http%3A%2F%2Fionicabizau.net)&year=2016#license-mit [website]: http://ionicabizau.net [contributing]: /CONTRIBUTING.md -[docs]: /DOCUMENTATION.md \ No newline at end of file +[docs]: /DOCUMENTATION.md