Issue #3223992 by SV: Add a check if there is optgroup array with items to prevent deleting the whole list of groups
Closes #3223992