本文整理汇总了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;
}