Skip to content

Commit 260b0f4

Browse files
author
Kamil Kisiela
committed
Merge branch 'release/v1.2.0'
2 parents 79465ff + be571b9 commit 260b0f4

File tree

6 files changed

+107
-5
lines changed

6 files changed

+107
-5
lines changed

.gitignore

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Created by .ignore support plugin (hsz.mobi)
2+
### Node template
3+
# Logs
4+
logs
5+
*.log
6+
npm-debug.log*
7+
8+
# Runtime data
9+
pids
10+
*.pid
11+
*.seed
12+
13+
# Directory for instrumented libs generated by jscoverage/JSCover
14+
lib-cov
15+
16+
# Coverage directory used by tools like istanbul
17+
coverage
18+
19+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
20+
.grunt
21+
22+
# node-waf configuration
23+
.lock-wscript
24+
25+
# Compiled binary addons (http://nodejs.org/api/addons.html)
26+
build/Release
27+
28+
# Dependency directory
29+
# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git
30+
node_modules
31+

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5+
## [1.2.0] - 2015-11-26
6+
### Added
7+
- **match** validator
8+
- **notmatch** validator
9+
510
## [1.1.1] - 2015-11-18
611
### Changed
712
- Refactor all files to use Strict Dependency Injection
@@ -53,6 +58,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
5358

5459
## 0.0.1 - 2015-11-09
5560

61+
[1.2.0]: https://github.com/wieldo/angular-formly-validator/compare/v1.1.1...v1.2.0
5662
[1.1.1]: https://github.com/wieldo/angular-formly-validator/compare/v1.1.0...v1.1.1
5763
[1.1.0]: https://github.com/wieldo/angular-formly-validator/compare/v1.0.0...v1.1.0
5864
[1.0.0]: https://github.com/wieldo/angular-formly-validator/compare/v0.0.4...v1.0.0

README.md

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ meteor add wieldo:angular-formly-validator
2121
## Getting Started
2222

2323
1. Add package using `meteor add` (see above)
24-
2. Add angular-formly files to your project
25-
3. Add the following dependencies to your AngularJS module:
24+
2. Add the following dependencies to your AngularJS module:
2625

2726
```javascript
2827
angular.module('myApp', [
@@ -45,7 +44,7 @@ formlyValidator.register('required', function(config, $viewValue, $modelValue, s
4544

4645
### Set validator for formly field
4746

48-
In field configuration, use structure below:
47+
In field configuration, use structure as in example below:
4948

5049
```
5150
{
@@ -140,6 +139,30 @@ Check if model does not match pattern (negation of pattern)
140139
}
141140
```
142141

142+
### match
143+
144+
Check if model matches the other model.
145+
146+
Field's key as a value.
147+
148+
```
149+
{
150+
match: <string>
151+
}
152+
```
153+
154+
### notmatch
155+
156+
Check if model does not match the other model (negation of match)
157+
158+
Field's key as a value.
159+
160+
```
161+
{
162+
notmatch: <string>
163+
}
164+
```
165+
143166
-
144167

145168
## Example

lib/client/validators/match.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
var {SetModule} = angular2now;
2+
3+
SetModule('formlyValidator')
4+
.run(['formlyValidator', (formlyValidator) => {
5+
6+
formlyValidator.register('match', (fieldKey, $viewValue, $modelValue, $scope) => {
7+
const value = $viewValue || $modelValue;
8+
9+
if (!angular.isString(fieldKey)) {
10+
throw formlyValidator.createError('match value has to be a string');
11+
}
12+
const field = _.find($scope.fields, (field) => field.key === fieldKey);
13+
14+
// force this setting
15+
$scope.options.extras.validateOnModelChange = true;
16+
17+
return formlyValidator.isEmpty($viewValue) || field.formControl.$viewValue === value;
18+
});
19+
20+
}]);

lib/client/validators/notmatch.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
var {SetModule} = angular2now;
2+
3+
SetModule('formlyValidator')
4+
.run(['formlyValidator', (formlyValidator) => {
5+
6+
formlyValidator.register('notmatch', (fieldKey, $viewValue, $modelValue, $scope) => {
7+
const value = $viewValue || $modelValue;
8+
9+
if (!angular.isString(fieldKey)) {
10+
throw formlyValidator.createError('match value has to be a string');
11+
}
12+
const field = _.find($scope.fields, (field) => field.key === fieldKey);
13+
14+
// force this setting
15+
$scope.options.extras.validateOnModelChange = true;
16+
17+
return formlyValidator.isEmpty($viewValue) || field.formControl.$viewValue !== value;
18+
});
19+
20+
}]);

package.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var client = 'client';
33
Package.describe({
44
name: "wieldo:angular-formly-validator",
55
summary: "Use set of built-in validators in your project. This module extends angular-formly-transformer.",
6-
version: "1.1.1",
6+
version: "1.2.0",
77

88
documentation: 'README.md',
99
git: 'https://github.com/wieldo/angular-formly-validator.git'
@@ -43,7 +43,9 @@ Package.onUse(function (api) {
4343
'lib/client/validators/minnumber.js',
4444
'lib/client/validators/maxnumber.js',
4545
'lib/client/validators/pattern.js',
46-
'lib/client/validators/notpattern.js'
46+
'lib/client/validators/notpattern.js',
47+
'lib/client/validators/match.js',
48+
'lib/client/validators/notmatch.js'
4749
], client);
4850

4951
});

0 commit comments

Comments
 (0)