Skip to content

Commit

Permalink
Do more in setExpression(...) #17 thanks @tammasr
Browse files Browse the repository at this point in the history
  • Loading branch information
hueitan committed May 31, 2014
1 parent a58a1c4 commit b1f875e
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 14 deletions.
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,7 @@ angular.module('yourApp', ['validation'])

// Setup `huei` validation
validationProvider.setExpression({

/**
* @param value , user input
* @returns {boolean} true iff valid
*/
huei: function (value) {
huei: function (value, scope, element, attrs) {
return value === 'Huei Tan';
// or you can do
return $q.all([obj]).then(function () {
Expand Down
24 changes: 19 additions & 5 deletions demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,7 @@
* Additions validation
*/
$validationProvider.setExpression({
/**
* @param value , user input
* @returns {boolean} true iff valid
*/
huei: function (value) {
huei: function (value, scope, element, attrs) {
return value === 'Huei Tan';
}
});
Expand All @@ -63,6 +59,24 @@
success: 'Thanks!'
}
});

/**
* Range Validation
*/
$validationProvider.setExpression({
range: function (value, scope, element, attrs) {
if (value >= parseInt(attrs.min) && value <= parseInt(attrs.max)) {
return value;
}
}
});

$validationProvider.setDefaultMsg({
range: {
error: 'Number should between 5 ~ 10',
success: 'good'
}
});
}])

// -------------------
Expand Down
2 changes: 1 addition & 1 deletion dist/angular-validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@

// Check with Function
if (expressionType === Function) {
return $q.all([$validationProvider.getExpression(validation)(value)])
return $q.all([$validationProvider.getExpression(validation)(value, scope, element, attrs)])
.then(function (data) {
if (data && data.length > 0 && data[0]) {
return valid.success();
Expand Down
2 changes: 1 addition & 1 deletion dist/angular-validation.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ <h1>Angular Validation.
</div>
</div>

<div class="row collapse">
<div class="small-12 columns">
<input type="text" validator="range" name="range" ng-model="form4.range" placeholder="number 5~10" min="5" max="10">
</div>
</div>
</fieldset>
</form>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@

// Check with Function
if (expressionType === Function) {
return $q.all([$validationProvider.getExpression(validation)(value)])
return $q.all([$validationProvider.getExpression(validation)(value, scope, element, attrs)])
.then(function (data) {
if (data && data.length > 0 && data[0]) {
return valid.success();
Expand Down

0 comments on commit b1f875e

Please sign in to comment.