From 17e906a6050bf8e62f6ad304eec65042dddfcced Mon Sep 17 00:00:00 2001 From: Huei Tan Date: Tue, 22 Jul 2014 00:05:40 +0800 Subject: [PATCH] Update readme file and add Q&A API page --- API.md | 241 ++++++++++++++++++++++++++++++++++++++++++++ Q&A.md | 24 +++++ README.md | 291 +++++------------------------------------------------- 3 files changed, 290 insertions(+), 266 deletions(-) create mode 100644 API.md create mode 100644 Q&A.md diff --git a/API.md b/API.md new file mode 100644 index 0000000..972c2b2 --- /dev/null +++ b/API.md @@ -0,0 +1,241 @@ +API +=== +**Add Valid Message (error, success) for validation `required`**
+`required-error-message` and `required-success-message` + +```html + + + +``` + +**Add Valid Message (error, success) for validation `email`**
+`email-error-message` and `email-success-message` + +```html + + +``` + +**Use Default Valid Message**
+*you don't need to give valid message* + +```html + + +``` + + +**Don't show the Valid Message `no-validation-message="true"`** + +```html + + + + +``` + +**Add Valid Callback Function, `invalid-callback` & `valid-callback`** + +```html + + +``` + +**Select the validation method `watch` `blur` `submit` `submit-only`, default as `watch`**
+`validationProvider.validate(form).success(callback).error(callback)` use callback to continue your submit + +```html + + + + + + + + +
+ + +
+ + +
+ + +
+ + + + + +
+ + +
+ + + + +``` + +**Setup a new Validation `setExpression()` `setDefaultMsg()` with `RegExp` or `Function` in config phase** + + +```html + + + + + + +``` + +```javascript +// your module +angular.module('yourApp', ['validation']) + .config(['$validationProvider', function ($validationProvider) { + // Setup `ip` validation + var expression = { + ip: /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/ + }; + + var validMsg = { + ip: { + error: 'This isn\'t ip address', + success: 'It\'s ip' + } + }; + + validationProvider.setExpression(expression) // set expression + .setDefaultMsg(validMsg); // set valid message + + // Setup `huei` validation + validationProvider + .setExpression({ + huei: function (value, scope, element, attrs) { + return value === 'Huei Tan'; + // or you can do + return $q.all([obj]).then(function () { + // ... + return true; + }) + } + }) + .setDefaultMsg({ + huei: { + error: 'This should be Huei Tan', + success: 'Thanks!' + } + }); + }]); +``` + +**Check form whether valid, return `true` if valid. `checkValid()`**
+**Reset the specific Form. `reset()`** + +```html +
+ ... + + + + + + + + +
+``` + +```javascript + // ... checkValid + $scope.form.checkValid = validationProvider.checkValid; + // ... reset + $scope.form.reset = function (form) { + validationProvider.reset(form); + }; + // ... angular validation 1.2.0 reset + $scope.form.reset = function () { + // Don't need include validationProvider.reset(); + // Focus on your ng-click action + }; +``` + +**Set the valid/invalid message style CSS** + +```html +

Your valid message here

+

Your invalid message here

+``` + +```css +.validation-valid { + +} + +.validation-invalid { + +} +``` + +**Custom the valid/invalid message style HTML in `.config()`,**
+`setErrorHTML(func)` `setSuccessHTML(func)`, input should be a `function` and given `parameter` which is the valid/invalid message declared +in `getDefaultMsg()`,and finally return the HTML code + +```javascript +// your angular +.config(['$validationProvider', function ($validationProvider) { + $validationProvider.setErrorHTML(function (msg) { + // remember to return your HTML + // eg: return '

' + msg + '

'; + }); + + $validationProvider.setSuccessHTML(function (msg) { + // eg: return '

' + msg + '

'; + }); +}]); +``` + +**disable/enable show success/error message**
+`default: true`
+Easily disable success/error message + +```javascript +// your angular +.config(['$validationProvider', function ($validationProvider) { + $validationProvider.showSuccessMessage = false; // or true(default) + $validationProvider.showErrorMessage = false; // or true(default) +}]); +``` + diff --git a/Q&A.md b/Q&A.md new file mode 100644 index 0000000..7b2cfd1 --- /dev/null +++ b/Q&A.md @@ -0,0 +1,24 @@ +Q & A +===== +###Can I validate the form when init ? [#10](https://github.com/huei90/angular-validation/issues/10)### + +```html +
+ + +
+``` +```javascript +$timeout(function () { // call $timeout to make sure the Form Constructor is generated + $validationProvider.validate($scope.Form); // $scope.Form is html form name `Form Constructor` +}); +``` + +###What's the differentiate between validator-method `submit` and `submit-only`[#4](https://github.com/huei90/angular-validation/issues/4)### + +`submit` : when user click submit, then start watching using `watch` to validate
+`submit-only` : when user click `submit`, doesn't validate through `watch` until `submit` button is clicked. + +###Use checkValid() manually [#19](https://github.com/huei90/angular-validation/issues/19)### + +Before using `checkValid()`, you have to execute `submit` first to get the latest result. \ No newline at end of file diff --git a/README.md b/README.md index 5b7e6b8..1b97ba8 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,10 @@ angular-validation 1.2.1 [![devDependency Status](https://david-dm.org/huei90/angular-validation/dev-status.png)](https://david-dm.org/huei90/angular-validation#info=devDependencies) [![Gitter chat](https://badges.gitter.im/huei90/angular-validation.png)](https://gitter.im/huei90/angular-validation) -Client-side Validation is easy.
-That's why **Angular Validation** is here!
-*Don't let Client-side Validation Crash your project.*
+Client-side Validation should be simple and clean. +
Don't let Client-side Validation dirty your controller. +
Setup your Validation on config phase by using some rules [(example)](https://github.com/huei90/angular-validation/blob/master/dist/angular-validation-rule.js) +
And add Validation in your view only. Requirement ----- @@ -44,246 +45,26 @@ angular.module('yourApp', ['validation']); angular.module('yourApp', ['validation', 'validation.rule']); ``` -Writing your Code +Writing your First Code ==== -**Add Valid Message (error, success) for validation `required`**
-`required-error-message` and `required-success-message` - -```html - - - -``` - -**Add Valid Message (error, success) for validation `email`**
-`email-error-message` and `email-success-message` - -```html - - -``` - -**Use Default Valid Message**
-*you don't need to give valid message* - -```html - - -``` - - -**Don't show the Valid Message `no-validation-message="true"`** - -```html - - - - -``` - -**Add Valid Callback Function, `invalid-callback` & `valid-callback`** - -```html - - -``` - -**Select the validation method `watch` `blur` `submit` `submit-only`, default as `watch`**
-`validationProvider.validate(form).success(callback).error(callback)` use callback to continue your submit - ```html - - - - - - - - -
- - -
- -
- - -
- - - - - -
- - -
- - - - -``` - -**Setup a new Validation `setExpression()` `setDefaultMsg()` with `RegExp` or `Function` in config phase** - - -```html - - - - - - -``` - -```javascript -// your module -angular.module('yourApp', ['validation']) - .config(['$validationProvider', function ($validationProvider) { - // Setup `ip` validation - var expression = { - ip: /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/ - }; - - var validMsg = { - ip: { - error: 'This isn\'t ip address', - success: 'It\'s ip' - } - }; - - validationProvider.setExpression(expression) // set expression - .setDefaultMsg(validMsg); // set valid message - - // Setup `huei` validation - validationProvider - .setExpression({ - huei: function (value, scope, element, attrs) { - return value === 'Huei Tan'; - // or you can do - return $q.all([obj]).then(function () { - // ... - return true; - }) - } - }) - .setDefaultMsg({ - huei: { - error: 'This should be Huei Tan', - success: 'Thanks!' - } - }); - }]); -``` - -**Check form whether valid, return `true` if valid. `checkValid()`**
-**Reset the specific Form. `reset()`** - -```html -
- ... - - - - - - - - -
-``` - -```javascript - // ... checkValid - $scope.form.checkValid = validationProvider.checkValid; - // ... reset - $scope.form.reset = function (form) { - validationProvider.reset(form); - }; - // ... angular validation 1.2.0 reset - $scope.form.reset = function () { - // Don't need include validationProvider.reset(); - // Focus on your ng-click action - }; -``` - -**Set the valid/invalid message style CSS** - -```html -

Your valid message here

-

Your invalid message here

-``` - -```css -.validation-valid { - -} - -.validation-invalid { - -} -``` - -**Custom the valid/invalid message style HTML in `.config()`,**
-`setErrorHTML(func)` `setSuccessHTML(func)`, input should be a `function` and given `parameter` which is the valid/invalid message declared -in `getDefaultMsg()`,and finally return the HTML code - -```javascript -// your angular -.config(['$validationProvider', function ($validationProvider) { - $validationProvider.setErrorHTML(function (msg) { - // remember to return your HTML - // eg: return '

' + msg + '

'; - }); - - $validationProvider.setSuccessHTML(function (msg) { - // eg: return '

' + msg + '

'; - }); -}]); -``` - -**disable/enable show success/error message**
-`default: true`
-Easily disable success/error message - -```javascript -// your angular -.config(['$validationProvider', function ($validationProvider) { - $validationProvider.showSuccessMessage = false; // or true(default) - $validationProvider.showErrorMessage = false; // or true(default) -}]); -``` +
+
+ + +
+
+ + +
+ + +
+ +``` + +[Documentation API](https://github.com/huei90/angular-validation/API.md) Built-in validation in angular-validation-rule === @@ -315,14 +96,12 @@ label.has-error.control-label { ``` - - Change the Error HTML to something like: ```javascript $validationProvider.setErrorHTML(function (msg) { - return ""; - }); + return ""; +}); ``` You can add the bootstrap class `.has-success` in a similar fashion. @@ -332,27 +111,7 @@ CHANGELOG ===== See [release](https://github.com/huei90/angular-validation/releases) -Q & A +CONTRIBUTORS ===== -###Can I validate the form when init ? [#10](https://github.com/huei90/angular-validation/issues/10)### - -```html -
- - -
-``` -```javascript -$timeout(function () { // call $timeout to make sure the Form Constructor is generated -$validationProvider.validate($scope.Form); // $scope.Form is html form name `Form Constructor` -}); -``` - -###What's the differentiate between validator-method `submit` and `submit-only`[#4](https://github.com/huei90/angular-validation/issues/4)### - -`submit` : when user click submit, then start watching using `watch` to validate
-`submit-only` : when user click `submit`, doesn't validate through `watch` until `submit` button is clicked. - -###When using checkValid() manually [#19](https://github.com/huei90/angular-validation/issues/19)### +Thanks for all [contributors](https://github.com/huei90/angular-validation/graphs/contributors) -Before using `checkValid()`, you have to execute `submit` first to get the latest result. \ No newline at end of file