forked from yuyang041060120/ng2-validation
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support libphonenumber yuyang041060120#23
- Loading branch information
jacky.yyy
committed
Apr 10, 2017
1 parent
4bb85d4
commit 0eaeb39
Showing
47 changed files
with
312 additions
and
393 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,51 @@ | ||
module.exports = function (config) { | ||
var _config = { | ||
basePath: './', | ||
|
||
frameworks: ['jasmine'], | ||
|
||
files: [ | ||
{pattern: './karma-test-shim.js', watched: false} | ||
], | ||
|
||
preprocessors: { | ||
'./karma-test-shim.js': ['webpack', 'sourcemap'] | ||
}, | ||
|
||
webpack: { | ||
resolve: { | ||
extensions: ['', '.ts', '.js'] | ||
}, | ||
module: { | ||
loaders: [ | ||
{ | ||
test: /\.ts$/, | ||
loader: 'ts' | ||
}, | ||
{ | ||
test: /\.html$/, | ||
loader: 'raw' | ||
} | ||
] | ||
} | ||
}, | ||
|
||
webpackMiddleware: { | ||
stats: 'errors-only' | ||
}, | ||
|
||
webpackServer: { | ||
noInfo: true | ||
}, | ||
|
||
reporters: ['progress'], | ||
port: 9876, | ||
colors: true, | ||
logLevel: config.LOG_INFO, | ||
autoWatch: false, | ||
browsers: ['PhantomJS'], | ||
singleRun: true | ||
}; | ||
|
||
config.set(_config); | ||
module.exports = function(config) { | ||
var _config = { | ||
basePath: './', | ||
|
||
frameworks: [ 'jasmine' ], | ||
|
||
files: [ | ||
{ pattern: './karma-test-shim.js', watched: false } | ||
], | ||
|
||
preprocessors: { | ||
'./karma-test-shim.js': [ 'webpack', 'sourcemap' ] | ||
}, | ||
|
||
webpack: { | ||
resolve: { | ||
extensions: [' ', '.js', '.ts'] | ||
}, | ||
module: { | ||
loaders: [ | ||
{ | ||
test: /\.ts$/, | ||
loader: 'ts-loader' | ||
}, | ||
{ | ||
test: /\.html$/, | ||
loader: 'raw-loader' | ||
} | ||
] | ||
} | ||
}, | ||
|
||
webpackMiddleware: { | ||
stats: 'errors-only' | ||
}, | ||
|
||
webpackServer: { | ||
noInfo: true | ||
}, | ||
|
||
reporters: [ 'progress' ], | ||
port: 9876, | ||
colors: true, | ||
logLevel: config.LOG_INFO, | ||
autoWatch: false, | ||
browsers: [ 'PhantomJS' ], | ||
singleRun: true | ||
}; | ||
|
||
config.set(_config); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// todo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Directive, Input, forwardRef, OnInit, OnChanges, SimpleChanges } from '@angular/core'; | ||
import { NG_VALIDATORS, Validator, ValidatorFn, AbstractControl } from '@angular/forms'; | ||
|
||
import { gt } from './'; | ||
|
||
const GREATER_THAN_VALIDATOR: any = { | ||
provide: NG_VALIDATORS, | ||
useExisting: forwardRef(() => GreaterThanValidator), | ||
multi: true | ||
}; | ||
|
||
@Directive({ | ||
selector: '[gt][formControlName],[gt][formControl],[gt][ngModel]', | ||
providers: [GREATER_THAN_VALIDATOR] | ||
}) | ||
export class GreaterThanValidator implements Validator, OnInit, OnChanges { | ||
@Input() gt: number; | ||
|
||
private validator: ValidatorFn; | ||
private onChange: () => void; | ||
|
||
ngOnInit() { | ||
this.validator = gt(this.gt); | ||
} | ||
|
||
ngOnChanges(changes: SimpleChanges) { | ||
for (let key in changes) { | ||
if (key === 'gt') { | ||
this.validator = gt(changes[key].currentValue); | ||
if (this.onChange) this.onChange(); | ||
} | ||
} | ||
} | ||
|
||
validate(c: AbstractControl): {[key: string]: any} { | ||
return this.validator(c); | ||
} | ||
|
||
registerOnValidatorChange(fn: () => void): void { | ||
this.onChange = fn; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './directive'; | ||
export * from './validator'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { FormControl } from '@angular/forms'; | ||
|
||
import { gt } from './'; | ||
|
||
describe('GT', () => { | ||
const error = {gt: true}; | ||
|
||
it('5 should be gt 3', () => { | ||
let control = new FormControl(5); | ||
|
||
expect(gt(3)(control)).toBeNull(); | ||
}); | ||
|
||
it('3 should not be gt 5', () => { | ||
let control = new FormControl(3); | ||
|
||
expect(gt(5)(control)).toEqual(error); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { AbstractControl, Validators, ValidatorFn } from '@angular/forms'; | ||
|
||
import { isPresent } from '../util/lang'; | ||
|
||
export const gt = (gt: number): ValidatorFn => { | ||
return (control: AbstractControl): {[key: string]: boolean} => { | ||
if (!isPresent(gt)) return null; | ||
if (isPresent(Validators.required(control))) return null; | ||
|
||
let v: number = +control.value; | ||
return v > +gt ? null : {gt: true}; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// todo |
Oops, something went wrong.