style checkboxes with bootstrap classes

This commit is contained in:
Thomas Rupprecht 2022-11-30 00:14:08 +01:00 committed by Igor Scheller
parent 0a1014496a
commit e8ccbd7c5e
4 changed files with 17 additions and 15 deletions

View File

@ -147,16 +147,17 @@ function admin_user()
. page_link_to('admin_user', ['action' => 'save_groups', 'id' => $user_id]) . page_link_to('admin_user', ['action' => 'save_groups', 'id' => $user_id])
. '" method="post">' . "\n"; . '" method="post">' . "\n";
$html .= form_csrf(); $html .= form_csrf();
$html .= '<table>'; $html .= '<div>';
$groups = changeableGroups($my_highest_group, $user_id); $groups = changeableGroups($my_highest_group, $user_id);
foreach ($groups as $group) { foreach ($groups as $group) {
$html .= '<tr><td><input type="checkbox" name="groups[]" value="' . $group->id . '" ' $html .= '<div class="form-check">'
. '<input class="form-check-input" type="checkbox" id="' . $group->id . '" name="groups[]" value="' . $group->id . '" '
. ($group->selected ? ' checked="checked"' : '') . ($group->selected ? ' checked="checked"' : '')
. ' /></td><td>' . $group->name . '</td></tr>'; . ' /><label class="form-check-label" for="' . $group->id . '">' . $group->name . '</label></div>';
} }
$html .= '</table><br>'; $html .= '</div><br>';
$html .= '<input type="submit" value="Speichern" class="btn btn-primary">' . "\n"; $html .= '<input type="submit" value="Speichern" class="btn btn-primary">' . "\n";
$html .= '</form>'; $html .= '</form>';

View File

@ -372,10 +372,11 @@ function make_select($items, $selected, $name, $title = null, $additionalButtons
$html .= buttons($buttons); $html .= buttons($buttons);
foreach ($items as $i) { foreach ($items as $i) {
$htmlItems[] = '<div class="checkbox">' $id = $name . '_' . $i['id'];
. '<label><input type="checkbox" name="' . $name . '[]" value="' . $i['id'] . '" ' $htmlItems[] = '<div class="form-check">'
. '<input class="form-check-input" type="checkbox" id="' . $id . '" name="' . $name . '[]" value="' . $i['id'] . '" '
. (in_array($i['id'], $selected) ? ' checked="checked"' : '') . (in_array($i['id'], $selected) ? ' checked="checked"' : '')
. ' > ' . $i['name'] . '</label>' . ' /><label class="form-check-label" for="' . $id . '">' . $i['name'] . '</label>'
. (!isset($i['enabled']) || $i['enabled'] ? '' : icon('book')) . (!isset($i['enabled']) || $i['enabled'] ? '' : icon('book'))
. '</div>'; . '</div>';
} }

View File

@ -175,9 +175,9 @@ function form_checkbox($name, $label, $selected, $value = 'checked', $html_id =
$html_id = $name; $html_id = $name;
} }
return '<div class="checkbox"><label>' return '<div class="form-check">'
. '<input type="checkbox" id="' . $html_id . '" name="' . $name . '" value="' . htmlspecialchars((string)$value) . '" ' . '<input class="form-check-input" type="checkbox" id="' . $html_id . '" name="' . $name . '" value="' . htmlspecialchars((string)$value) . '" '
. ($selected ? ' checked="checked"' : '') . ' /> ' . ($selected ? ' checked="checked"' : '') . ' /><label class="form-check-label" for="' . $html_id . '">'
. $label . $label
. '</label></div>'; . '</label></div>';
} }

View File

@ -74,11 +74,11 @@
{% macro checkbox(name, label, checked, value, disabled, raw_label) %} {% macro checkbox(name, label, checked, value, disabled, raw_label) %}
<div class="form-check mb-3"> <div class="form-check mb-3">
<label> <input class="form-check-input" type="checkbox" id="{{ name }}" name="{{ name }}" value="{{ value|default('1') }}"
<input type="checkbox" id="{{ name }}" name="{{ name }}" value="{{ value|default('1') }}" class="form-check-input"
{%- if checked|default(false) %} checked{% endif %} {%- if checked|default(false) %} checked{% endif %}
{%- if disabled|default(false) %} disabled{% endif %} {%- if disabled|default(false) %} disabled{% endif %}
> />
<label class="form-check-label" for="{{ name }}">
{%- if raw_label|default(false) -%} {%- if raw_label|default(false) -%}
{{ label|raw }} {{ label|raw }}
{%- else -%} {%- else -%}