mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-12 04:23:04 +00:00
bug fixing
This commit is contained in:
@@ -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 } }
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user