mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-01-03 12:39:25 +01:00
Et2Select: Fix missing options filter to handle option groups too
This commit is contained in:
parent
eddcc97163
commit
6ecb2d8cf9
@ -527,7 +527,31 @@ export class Et2Select extends Et2WithSearchMixin(Et2WidgetWithSelect)
|
||||
{
|
||||
if(!this.readonly && value && value.length > 0 && !this.allowFreeEntries && this.select_options.length > 0)
|
||||
{
|
||||
const missing = value.filter(v => !this.select_options.some(option => option.value == v));
|
||||
function filterBySelectOptions(arrayToFilter, options : SelectOption[])
|
||||
{
|
||||
const filteredArray = arrayToFilter.filter(item =>
|
||||
{
|
||||
// Check if item is found in options
|
||||
return !options.some(option =>
|
||||
{
|
||||
if(typeof option.value === 'string')
|
||||
{
|
||||
// Regular option
|
||||
return option.value === item;
|
||||
}
|
||||
else if(Array.isArray(option.value))
|
||||
{
|
||||
// Recursively check if item is found in nested array (option groups)
|
||||
return filterBySelectOptions([item], option.value).length > 0;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
});
|
||||
|
||||
return filteredArray;
|
||||
}
|
||||
|
||||
const missing = filterBySelectOptions(value, this.select_options);
|
||||
if(missing.length > 0)
|
||||
{
|
||||
console.warn("Invalid option '" + missing.join(", ") + " ' removed");
|
||||
|
@ -1,6 +1,13 @@
|
||||
/**
|
||||
* Interface for select options
|
||||
*
|
||||
* While we can (mostly) handle key => value maps, this is the preferred way to specify selectable options.
|
||||
* For option groups, value is the list of sub-options.
|
||||
*
|
||||
*/
|
||||
export interface SelectOption
|
||||
{
|
||||
value : string;
|
||||
value : string | SelectOption[];
|
||||
label : string;
|
||||
// Hover help text
|
||||
title? : string;
|
||||
|
Loading…
Reference in New Issue
Block a user