59334: edit item metadata finished

This commit is contained in:
lotte
2019-02-13 11:39:32 +01:00
parent 714811dc07
commit 7eec961fa7
14 changed files with 233 additions and 98 deletions

View File

@@ -0,0 +1,32 @@
import { Directive, Input } from '@angular/core';
import { FormControl, NG_VALIDATORS, ValidationErrors, Validator } from '@angular/forms';
import { inListValidator } from './validator.functions';
/**
* Directive for validating if a ngModel value is in a given list
*/
@Directive({
selector: '[ngModel][dsInListValidator]',
// We add our directive to the list of existing validators
providers: [
{ provide: NG_VALIDATORS, useExisting: InListValidator, multi: true }
]
})
export class InListValidator implements Validator {
/**
* The list to look in
*/
@Input()
dsInListValidator: string[];
/**
* The function that checks if the form control's value is currently valid
* @param c The FormControl
*/
validate(c: FormControl): ValidationErrors | null {
if (this.dsInListValidator !== null) {
return inListValidator(this.dsInListValidator)(c);
}
return null;
}
}

View File

@@ -1,7 +1,11 @@
import { AbstractControl, ValidatorFn } from '@angular/forms';
/**
* Returns a validator function to check if the control's value is in a given list
* @param list The list to look in
*/
export function inListValidator(list: string[]): ValidatorFn {
return (control: AbstractControl): {[key: string]: any} | null => {
const contains = list.indexOf(control.value) > 0;
const contains = list.indexOf(control.value) > -1;
return contains ? null : {inList: {value: control.value}} };
}