mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-01-20 04:48:49 +01:00
Et2Select: Fix missing options filter to handle option groups too
This commit is contained in:
parent
c5ec9ff8d8
commit
da2413a07f
@ -527,7 +527,31 @@ export class Et2Select extends Et2WithSearchMixin(Et2WidgetWithSelect)
|
|||||||
{
|
{
|
||||||
if(!this.readonly && value && value.length > 0 && !this.allowFreeEntries && this.select_options.length > 0)
|
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)
|
if(missing.length > 0)
|
||||||
{
|
{
|
||||||
console.warn("Invalid option '" + missing.join(", ") + " ' removed");
|
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
|
export interface SelectOption
|
||||||
{
|
{
|
||||||
value : string;
|
value : string | SelectOption[];
|
||||||
label : string;
|
label : string;
|
||||||
// Hover help text
|
// Hover help text
|
||||||
title? : string;
|
title? : string;
|
||||||
|
Loading…
Reference in New Issue
Block a user