Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { Directive, Input, OnInit } from '@angular/core';
import { FormControl, NG_VALIDATORS, Validator, Validators } from '@angular/forms';
import { forbiddenValuesValidator } from './forbidden-values-validator';
@Directive({
// tslint:disable-next-line
selector: '[forbiddenValues]',
providers: [{ provide: NG_VALIDATORS, useExisting: ForbiddenValuesDirective, multi: true }],
})
export class ForbiddenValuesDirective implements OnInit, Validator {
@Input()
public forbiddenValues: string[];
private validator = Validators.nullValidator;
public ngOnInit(): void {
this.validator = forbiddenValuesValidator(this.forbiddenValues);
}
public validate(c: FormControl): { [key: string]: any } {
return this.validator(c);
}
}
ngOnInit() {
this.loginError$ = this.accountFacade.userError$;
const loginValidator = this.loginType === 'email' ? CustomValidators.email : Validators.nullValidator;
this.form = new FormGroup({
login: new FormControl('', [Validators.required, loginValidator]),
password: new FormControl('', Validators.required),
});
}
ngOnChanges(changes: SimpleChanges): void {
const change = changes['targetExists'];
if (change) {
const target: string = change.currentValue;
this.valFn = this.targetExistsValidator(target);
} else {
this.valFn = Validators.nullValidator;
}
}
validate(control: AbstractControl): {[key: string]: any} {
validate(control: AbstractControl): { [key: string]: any } {
return this.valFn(control) || Validators.nullValidator;
}
}
/**
* When used as standalone without form-group you can set FormGroup, otherwise it is set from
* parent
*/
@Input() get formGroup(): FormGroup {
return this._formGroup;
}
set formGroup(value: FormGroup) {
this._formGroup = value;
this.initFormControl();
this._cd.markForCheck();
}
@Input()
validators: Array = [Validators.nullValidator];
@Input()
rank: number;
@Input()
placeholder: string;
@Input()
fluid: boolean = false;
/**
* This is in most of the cases set from parent container (form-group)
*/
@Input()
i18Strings: TemplateRef;
import { Observable } from 'rxjs';
import { ProjectDefaultService, ProjectService } from "../../lib/services";
@Directive({
selector: '[targetExists]',
providers: [
MemberService,
{ provide: ProjectService, useClass: ProjectDefaultService },
{ provide: NG_ASYNC_VALIDATORS, useExisting: TargetExistsValidatorDirective, multi: true },
]
})
export class TargetExistsValidatorDirective implements Validator, OnChanges {
@Input() targetExists: string;
@Input() projectId: number;
valFn = Validators.nullValidator;
constructor(
private projectService: ProjectService,
private memberService: MemberService) { }
ngOnChanges(changes: SimpleChanges): void {
const change = changes['targetExists'];
if (change) {
const target: string = change.currentValue;
this.valFn = this.targetExistsValidator(target);
} else {
this.valFn = Validators.nullValidator;
}
}
validate(control: AbstractControl): { [key: string]: any } {
return this.valFn(control);
public set isRequired(value: boolean) {
const validator =
value ?
Validators.required :
Validators.nullValidator;
this.renameForm.controls['name'].setValidators(validator);
}
public load(value: Partial) {
if (value) {
this.form.controls['password'].setValidators(Validators.nullValidator);
} else {
this.form.controls['password'].setValidators(Validators.required);
}
super.load(value);
}
checkIsLabsDB(){
this.cmdbForm.setControl("userName",new FormControl('',Validators.required));
this.cmdbForm.setControl("passwordInput",new FormControl('',Validators.required));
if(this.cmdbConfig.type == "Labsdb"){
this.cmdbForm.setControl("userName",new FormControl('',Validators.nullValidator));
this.cmdbForm.setControl("passwordInput",new FormControl('',Validators.nullValidator));
}else if(this.cmdbConfig.type == "InfoBlox"){
this.isInfoblox = true;
if(this.cmdbConfig.advanceSetting != null && this.cmdbConfig.advanceSetting.INFOBLOX_PROXY_SEARCH != ""){
this.enableProxySearch = true;
this.advanceSetting = this.cmdbConfig.advanceSetting;
}
}
}
import 'rxjs/add/operator/map'
import { HttpClient } from '@angular/common/http';
import { AppInitService } from '../../app.init.service';
import { MessageService } from '../message-service/message.service';
@Directive({
selector: '[checkItemExisting]',
providers: [
{provide: NG_ASYNC_VALIDATORS, useExisting: CheckItemExistingDirective, multi: true}
]
})
export class CheckItemExistingDirective implements AsyncValidator {
@Input() checkItemExisting;
@Input() userID: number = 0;
valFn: ValidatorFn = Validators.nullValidator;
constructor(private http: HttpClient,
private appInitService: AppInitService,
private messageService: MessageService) {
}
checkUserExists(target: string, value: string, userID: number): Observable<{[key: string]: any}> {
return this.http.get("/api/v1/user-exists", {
observe: "response",
params: {
'target': target,
'value': value,
'user_id': userID.toString()
}
})
.map(()=>this.valFn)