Skip to content
Snippets Groups Projects
Commit 894de7bc authored by Elmar Ludwig's avatar Elmar Ludwig Committed by Jan-Hendrik Willms
Browse files

add data-formaction attribute for submit-upon-select, fixes #3115

Closes #3115

Merge request studip/studip!2097
parent e7842647
No related branches found
No related tags found
No related merge requests found
......@@ -75,20 +75,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));
}
if (isset($widget->attributes) && is_array($widget->attributes)) {
$widget->attributes = array_merge($widget->attributes, $attributes);
} else {
$widget->attributes = $attributes;
foreach ($options as $value => $option) {
$selected = $value === $selected_option ? 'selected' : '';
$option_content .= sprintf(
'<option value="%s" %s>%s</option>',
htmlReady($value),
$selected,
htmlReady($option)
);
}
$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));
}
......
......@@ -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();
return false;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment