diff --git a/lib/classes/sidebar/OptionsWidget.php b/lib/classes/sidebar/OptionsWidget.php index a3660b5cc8c53ffb7efbc6ed6820bbfda43630e1..304a5ac26cabc0b149de4b8d79fd2af2bd9d120f 100644 --- a/lib/classes/sidebar/OptionsWidget.php +++ b/lib/classes/sidebar/OptionsWidget.php @@ -77,20 +77,26 @@ class OptionsWidget extends ListWidget */ public function addSelect($label, $url, $name, $options, $selected_option = false, $attributes = []) { - $widget = new SelectWidget($label, $url, $name); - $widget->layout = false; + $option_content = ''; - foreach ($options as $value => $option_label) { - $widget->addElement(new SelectElement($value, $option_label, $value === $selected_option)); + foreach ($options as $value => $option) { + $selected = $value === $selected_option ? 'selected' : ''; + $option_content .= sprintf( + '<option value="%s" %s>%s</option>', + htmlReady($value), + $selected, + htmlReady($option) + ); } - if (isset($widget->attributes) && is_array($widget->attributes)) { - $widget->attributes = array_merge($widget->attributes, $attributes); - } else { - $widget->attributes = $attributes; - } - - $content = $widget->render(); + $content = sprintf( + '<select data-formaction="%s" class="sidebar-selectlist submit-upon-select" name="%s" aria-label="%s" %s>%s</select>', + htmlReady($url), + htmlReady($name), + htmlReady($label), + arrayToHtmlAttributes($attributes), + $option_content + ); $this->addElement(new WidgetElement($content)); } diff --git a/resources/assets/javascripts/bootstrap/forms.js b/resources/assets/javascripts/bootstrap/forms.js index cffc17d9d634a1da412906d3eeff5d7fc2f3b93f..16e403191dd4c4378e84e9f9513ba8f6c7ef912f 100644 --- a/resources/assets/javascripts/bootstrap/forms.js +++ b/resources/assets/javascripts/bootstrap/forms.js @@ -107,6 +107,9 @@ $(document) // Submit only if value has changed and either enter was pressed or // select was opened by click if (!is_default && shouldSubmit) { + if ($(this).data('formaction')) { + $(this.form).attr('action', $(this).data('formaction')); + } $(this.form).submit(); $('option', this).prop('defaultSelected', false).filter(':selected').prop('defaultSelected', true); return false;