Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;
}
}
buildAngleSpanForm() {
this.angleSpanForm = this.fb.group({
angleSpan: [
this.chart.angle_span,
Validators.compose([
Validators.required,
services.ValidationService.integerValidator,
Validators.min(0)
])
]
});
this.angleSpan = this.angleSpanForm.controls['angleSpan'];
this.angleSpanChange.emit({
angleSpanValid: this.angleSpanForm.valid
});
}
formInit() {
this.form = this.fb.group({
username: ['', [Validators.required]],
realname: ['', [Validators.required]],
mobile: ['', [Validators.required]],
profile: ['', [Validators.required]],
avatar: ['', [Validators.required]],
id: ['', [Validators.required]],
status: ['', [Validators.min(1), Validators.max(2)]],
});
}
constructor(private route: ActivatedRoute,
private perUnitRevenueInformationService: PerUnitRevenueInformationService,
private router: Router,
fb: FormBuilder) {
this.infoGroup = fb.group({
adultLikeCount: [1, [Validators.required, Validators.min(1)]],
childCount: [0, [Validators.required, Validators.min(0)]],
monoParental: [false],
});
}
private _updateValidators() {
const validatorGroup: any[] = [];
const parameterTemplate = this.parameter.param;
if (parameterTemplate.type === NcjParameterRawType.int) {
if (parameterTemplate.minValue) {
validatorGroup.push(Validators.min(parameterTemplate.minValue));
}
if (parameterTemplate.maxValue) {
validatorGroup.push(Validators.max(parameterTemplate.maxValue));
}
}
if (parameterTemplate.type === NcjParameterRawType.string) {
if (parameterTemplate.minLength) {
validatorGroup.push(Validators.minLength(parameterTemplate.minLength));
}
if (parameterTemplate.maxLength) {
validatorGroup.push(Validators.maxLength(parameterTemplate.maxLength));
}
}
this.parameterValue.setValidators(Validators.compose(validatorGroup));
this.inputValidatorFns.push(Validators.pattern(InputPatternNumber));
}
if (this.inputIsRequired) {
this.inputValidatorFns.push(Validators.required);
}
if (this.inputMaxlength > 0) {
this.inputValidatorFns.push(Validators.maxLength(this.inputMaxlength));
}
if (this.inputMinlength > 0) {
this.inputValidatorFns.push(Validators.minLength(this.inputMinlength));
}
if (this.inputMax > 0) {
this.inputValidatorFns.push(Validators.max(this.inputMax));
}
if (this.inputMin > 0) {
this.inputValidatorFns.push(Validators.min(this.inputMin));
}
if (this.inputPattern) {
this.inputValidatorFns.push(Validators.pattern(this.inputPattern));
}
if (this.customerValidatorFns) {
this.customerValidatorFns.forEach(value => {
this.inputValidatorFns.push(value);
})
}
}
const groupConfig = sets.reduce((group, set) => {
group[set.jobId] = [set.level, [Validators.required, Validators.min(1)]];
return group;
}, {});
return fb.group(groupConfig);
buildForm(): void {
this.updateQuerySizeLimitForm = this.fb.group({
querySizeLimit: [
this.querySizeLimit,
Validators.compose([
Validators.required,
Validators.min(0),
Validators.maxLength(255)
])
]
});
}
private setCompressionValidators() {
CdValidators.validateIf(this.form.get('minBlobSize'), () => this.hasCompressionEnabled(), [
Validators.min(0),
CdValidators.custom('maximum', (size) =>
this.oddBlobSize(size, this.form.getValue('maxBlobSize'))
)
]);
CdValidators.validateIf(this.form.get('maxBlobSize'), () => this.hasCompressionEnabled(), [
Validators.min(0),
CdValidators.custom('minimum', (size) =>
this.oddBlobSize(this.form.getValue('minBlobSize'), size)
)
]);
CdValidators.validateIf(this.form.get('ratio'), () => this.hasCompressionEnabled(), [
Validators.min(0),
Validators.max(1)
]);
}