bug fixing

This commit is contained in:
lotte
2019-02-25 09:57:46 +01:00
parent 3c104a460b
commit 35be122eea
13 changed files with 93 additions and 80 deletions

View File

@@ -1,11 +1,17 @@
import { AbstractControl, ValidatorFn } from '@angular/forms';
import { isNotEmpty } from '../empty.util';
/**
* 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) > -1;
return contains ? null : {inList: {value: control.value}} };
return (control: AbstractControl): { [key: string]: any } | null => {
const hasValue = isNotEmpty(control.value);
let inList = true;
if (isNotEmpty(list)) {
inList = list.indexOf(control.value) > -1;
}
return (hasValue && inList) ? null : { inList: { value: control.value } }
};
}