本文整理匯總了TypeScript中@angular/forms.Validators.max方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Validators.max方法的具體用法?TypeScript Validators.max怎麽用?TypeScript Validators.max使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類@angular/forms.Validators
的用法示例。
在下文中一共展示了Validators.max方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: ngOnInit
ngOnInit() {
this.categoriesObs = this.ds.categories;
this.vehiculeForm = this.fb.group({
immatriculation: [
'',
[
Validators.required,
Validators.pattern(/^[A-Z][A-Z]-\d\d\d-[A-Z][A-Z]$/)
]
],
marque: ['', Validators.required],
modele: ['', Validators.required],
categorie: ['', Validators.required],
nbPlaces: [
'',
[
Validators.required,
Validators.max(20),
Validators.min(1),
Validators.pattern(/^\d+$/)
]
],
photo: ['', Validators.required]
});
}
示例2: createValidators
/**
* Creates form validationdepending [ITdDynamicElementConfig] properties.
*/
createValidators(config: ITdDynamicElementConfig): ValidatorFn {
let validator: ValidatorFn;
if (config.required) {
validator = Validators.required;
}
if (config.max || config.max === 0) {
validator = Validators.compose([validator, Validators.max(parseFloat(config.max))]);
}
if (config.min || config.min === 0) {
validator = Validators.compose([validator, Validators.min(parseFloat(config.min))]);
}
if (config.maxLength || config.maxLength === 0) {
validator = Validators.compose([validator, Validators.maxLength(parseFloat(config.maxLength))]);
}
if (config.minLength || config.minLength === 0) {
validator = Validators.compose([validator, Validators.minLength(parseFloat(config.minLength))]);
}
// Add provided custom validators to the validator function
if (config.validators) {
config.validators.forEach((validatorConfig: ITdDynamicElementValidator) => {
validator = Validators.compose([validator, validatorConfig.validator]);
});
}
return validator;
}
示例3: validate
validate(c: AbstractControl): { [key: string]: any; } {
if (this.element.nativeElement.max) {
const max = parseInt(this.element.nativeElement.max, 10 );
return Validators.max(max)(c);
}
return null;
}
示例4: ngOnInit
ngOnInit() {
this.personalInfoForm = this.formBuilder.group(
{
name: ['', [Validators.required, Validators.pattern(/[a-zA-Z].*/)]],
surname: ['', [Validators.required, Validators.pattern(/[a-zA-Z].*/)]],
age: ['', [Validators.required, Validators.min(1),Validators.max(99)]],
})
}
示例5: constructor
constructor (private i18n: I18n) {
this.INSTANCE_NAME = {
VALIDATORS: [ Validators.required ],
MESSAGES: {
'required': this.i18n('Instance name is required.')
}
}
this.INSTANCE_SHORT_DESCRIPTION = {
VALIDATORS: [ Validators.max(250) ],
MESSAGES: {
'max': this.i18n('Short description should not be longer than 250 characters.')
}
}
this.SERVICES_TWITTER_USERNAME = {
VALIDATORS: [ Validators.required ],
MESSAGES: {
'required': this.i18n('Twitter username is required.')
}
}
this.CACHE_PREVIEWS_SIZE = {
VALIDATORS: [ Validators.required, Validators.min(1), Validators.pattern('[0-9]+') ],
MESSAGES: {
'required': this.i18n('Previews cache size is required.'),
'min': this.i18n('Previews cache size must be greater than 1.'),
'pattern': this.i18n('Previews cache size must be a number.')
}
}
this.SIGNUP_LIMIT = {
VALIDATORS: [ Validators.required, Validators.min(1), Validators.pattern('[0-9]+') ],
MESSAGES: {
'required': this.i18n('Signup limit is required.'),
'min': this.i18n('Signup limit must be greater than 1.'),
'pattern': this.i18n('Signup limit must be a number.')
}
}
this.ADMIN_EMAIL = {
VALIDATORS: [ Validators.required, Validators.email ],
MESSAGES: {
'required': this.i18n('Admin email is required.'),
'email': this.i18n('Admin email must be valid.')
}
}
this.TRANSCODING_THREADS = {
VALIDATORS: [ Validators.required, Validators.min(1) ],
MESSAGES: {
'required': this.i18n('Transcoding threads is required.'),
'min': this.i18n('Transcoding threads must be greater than 1.')
}
}
}
示例6: ngOnInit
ngOnInit() {
this.createForm = this.fb.group({
make: ["", [Validators.minLength(4), Validators.required]],
model: ["", [Validators.minLength(4), Validators.required]],
year: ["", [Validators.min(1950), Validators.max(2050)]],
description: ["", [Validators.minLength(11)]],
price: ["", [Validators.min(1)]],
imageUrl: ["", [Validators.required]],
material: [""]
});
}
示例7: constructor
constructor(
private tokenService: AngularTokenService,
private gameService: GameService,
private router: Router,
private formBuilder: FormBuilder,
) {
this.createForm = this.formBuilder.group({
name: ['', [Validators.required, Validators.minLength(4), Validators.maxLength(128)]],
numberOfPlayers: [4, [Validators.required, Validators.min(1), Validators.max(8)]]
});
}
示例8: it
it('should always validate the permanentValidators', () => {
CdValidators.validateIf(
form.get('x'),
() => ((form && form.getValue('y')) || 0) > 10,
[Validators.min(7), Validators.max(12)],
[Validators.required],
[form.get('y')]
);
formHelper.expectValid('x');
formHelper.setValue('x', '');
formHelper.expectError('x', 'required');
});
示例9: getValidators
protected getValidators() {
const validators = new Array<ValidatorFn>();
if (this._definition.validationDefinition.isRequired) {
validators.push(Validators.required);
}
const min = this._definition.validationDefinition.min;
if (min || min === 0) {
validators.push(Validators.min(min as number));
}
const max = this._definition.validationDefinition.max;
if (max || max === 0) {
validators.push(Validators.max(max as number));
}
return validators;
}