public function addOptionsWithGroups($optionGroups = [], $selectedValue = '')
    {
        // Create all options
        foreach ($optionGroups as $groupLabel => $options) {
            // Create option group
            $og = $this->getHTMLFormFactory()->buildFormElement('optgroup', $name = '', $value = '', $id = '', $class = '', $itemValue = '');
            $og->attr('label', $groupLabel);

            // Create all options
            foreach ($options as $value => $title) {
                // Create option
                $fi = $this->getHTMLFormFactory()->buildFormElement('option', '', $value, '', '', $title);

                // Check if it's the selected value
                if ($value == $selectedValue) {
                    $fi->attr('selected', 'selected');
                }

                // Append option to group
                $og->append($fi);
            }

            // Append option group to select
            $this->append($og);
        }

        // Return FormSelect object
        return $this;
    }