Add required text next to required fields

This commit is contained in:
rubenwardy 2023-08-20 23:33:39 +01:00
parent bb719ad844
commit 4433918d4c
5 changed files with 50 additions and 23 deletions

@ -9,7 +9,6 @@ function updateOrder() {
.map(x => x.dataset.id) .map(x => x.dataset.id)
.filter(x => x); .filter(x => x);
console.log(ids);
document.querySelector("input[name='order']").value = ids.join(","); document.querySelector("input[name='order']").value = ids.join(",");
} }

@ -4,12 +4,30 @@
{% endfor %} {% endfor %}
{% endmacro %} {% endmacro %}
{% macro render_label(field, label=None, label_visible=true) %}
{% if field.type != 'HiddenField' %}
{% if not label and label != "" %}{% set label=field.label.text %}{% endif %}
{% if label %}
<label for="{{ field.id }}" {% if not label_visible %}class="sr-only"{% endif %}>
{{ label|safe }}
</label>
{% if field.flags.required and label_visible %}
<span class="ml-1 text-danger">
<small>
<i class="fas fa-asterisk"></i>
</small>
</span>
<span class="ml-3 text-muted">
{{ _("Required") }}
</span>
{% endif %}
{% endif %}
{% endif %}
{% endmacro %}
{% macro render_field(field, label=None, label_visible=true, right_url=None, right_label=None, fieldclass=None, hint=None) -%} {% macro render_field(field, label=None, label_visible=true, right_url=None, right_label=None, fieldclass=None, hint=None) -%}
<div class="form-group {% if field.errors %}has-danger{% endif %} {{ kwargs.pop('class_', '') }}"> <div class="form-group {% if field.errors %}has-danger{% endif %} {{ kwargs.pop('class_', '') }}">
{% if field.type != 'HiddenField' %} {{ render_label(field, label, label_visible) }}
{% if not label and label != "" %}{% set label=field.label.text %}{% endif %}
{% if label %}<label for="{{ field.id }}" {% if not label_visible %}class="sr-only"{% endif %}>{{ label|safe }}</label>{% endif %}
{% endif %}
{{ field(class_=fieldclass or 'form-control', **kwargs) }} {{ field(class_=fieldclass or 'form-control', **kwargs) }}
{% if hint %} {% if hint %}
<small class="form-text text-muted">{{ hint | safe }}</small> <small class="form-text text-muted">{{ hint | safe }}</small>
@ -20,11 +38,7 @@
{% macro render_field_prefix(field, label=None, prefix="@", label_visible=true, right_url=None, right_label=None, fieldclass=None) -%} {% macro render_field_prefix(field, label=None, prefix="@", label_visible=true, right_url=None, right_label=None, fieldclass=None) -%}
<div class="form-group {% if field.errors %}has-danger{% endif %} {{ kwargs.pop('class_', '') }}"> <div class="form-group {% if field.errors %}has-danger{% endif %} {{ kwargs.pop('class_', '') }}">
{% if field.type != 'HiddenField' and label_visible %} {{ render_label(field, label, label_visible) }}
{% if not label and label != "" %}{% set label=field.label.text %}{% endif %}
{% if label %}<label for="{{ field.id }}">{{ label|safe }}</label>{% endif %}
{% endif %}
<div class="input-group mb-3"> <div class="input-group mb-3">
<div class="input-group-prepend"> <div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1">{{ prefix }}</span> <span class="input-group-text" id="basic-addon1">{{ prefix }}</span>
@ -38,11 +52,7 @@
{% macro render_field_prefix_button(field, label=None, prefix="@", label_visible=true, right_url=None, right_label=None, fieldclass=None, has_view=False, hint=None) -%} {% macro render_field_prefix_button(field, label=None, prefix="@", label_visible=true, right_url=None, right_label=None, fieldclass=None, has_view=False, hint=None) -%}
<div class="form-group {% if field.errors %}has-danger{% endif %} {{ kwargs.pop('class_', '') }}"> <div class="form-group {% if field.errors %}has-danger{% endif %} {{ kwargs.pop('class_', '') }}">
{% if field.type != 'HiddenField' and label_visible %} {{ render_label(field, label, label_visible) }}
{% if not label and label != "" %}{% set label=field.label.text %}{% endif %}
{% if label %}<label for="{{ field.id }}">{{ label|safe }}</label>{% endif %}
{% endif %}
<div class="input-group mb-1"> <div class="input-group mb-1">
<div class="input-group-prepend"> <div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1">{{ prefix }}</span> <span class="input-group-text" id="basic-addon1">{{ prefix }}</span>
@ -104,10 +114,7 @@
{% macro render_multiselect_field(field, label=None, label_visible=true, right_url=None, right_label=None) -%} {% macro render_multiselect_field(field, label=None, label_visible=true, right_url=None, right_label=None) -%}
<div class="form-group {% if field.errors %}has-danger{% endif %} {{ kwargs.pop('class_', '') }}"> <div class="form-group {% if field.errors %}has-danger{% endif %} {{ kwargs.pop('class_', '') }}">
{% if field.type != 'HiddenField' and label_visible %} {{ render_label(field, label, label_visible) }}
{% if not label %}{% set label=field.label.text %}{% endif %}
<label for="{{ field.id }}">{{ label|safe }}</label>
{% endif %}
<div class="multichoice_selector bulletselector form-control"> <div class="multichoice_selector bulletselector form-control">
<input type="text" placeholder="{{ _('Start typing to see suggestions') }}"> <input type="text" placeholder="{{ _('Start typing to see suggestions') }}">
<div class="clearboth"></div> <div class="clearboth"></div>
@ -129,10 +136,7 @@
{% macro render_radio_field(field, hint=None, label=None, label_visible=true) -%} {% macro render_radio_field(field, hint=None, label=None, label_visible=true) -%}
<div class="form-group {% if field.errors %}has-danger{% endif %} {{ kwargs.pop('class_', '') }}"> <div class="form-group {% if field.errors %}has-danger{% endif %} {{ kwargs.pop('class_', '') }}">
{% if label_visible %} {{ render_label(field, label, label_visible) }}
{% if not label and label != "" %}{% set label=field.label.text %}{% endif %}
{% if label %}<label for="{{ field.id }}">{{ label|safe }}</label>{% endif %}
{% endif %}
{% for value, label, checked in field.iter_choices() %} {% for value, label, checked in field.iter_choices() %}
<div class="form-check my-1"> <div class="form-check my-1">
<label class="form-check-label"> <label class="form-check-label">

@ -132,6 +132,14 @@
<div class="form-group"> <div class="form-group">
<label for="title">{{ _("Title") }}</label> <label for="title">{{ _("Title") }}</label>
<span class="ml-1 text-danger">
<small>
<i class="fas fa-asterisk"></i>
</small>
</span>
<span class="ml-3 text-muted">
{{ _("Required") }}
</span>
<input class="form-control" id="title" name="title" required="" type="text"> <input class="form-control" id="title" name="title" required="" type="text">
</div> </div>

@ -25,6 +25,14 @@ Remove {{ package.title }}
<div class="form-group"> <div class="form-group">
<label for="reason">{{ _("Reason") }}</label> <label for="reason">{{ _("Reason") }}</label>
<span class="ml-1 text-danger">
<small>
<i class="fas fa-asterisk"></i>
</small>
</span>
<span class="ml-3 text-muted">
{{ _("Required") }}
</span>
<input id="reason" class="form-control" type="text" name="reason" required minlength="5"> <input id="reason" class="form-control" type="text" name="reason" required minlength="5">
<small class="form-text text-muted"> <small class="form-text text-muted">
{{ _("Reason for unapproval / deletion, this is shown in the audit log") }} {{ _("Reason for unapproval / deletion, this is shown in the audit log") }}

@ -60,6 +60,14 @@
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" /> <input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<div class="form-group"> <div class="form-group">
<label for="message">{{ _("Message") }}</label> <label for="message">{{ _("Message") }}</label>
<span class="ml-1 text-danger">
<small>
<i class="fas fa-asterisk"></i>
</small>
</span>
<span class="ml-3 text-muted">
{{ _("Required") }}
</span>
<input id="message" class="form-control" type="text" name="message" required minlength="5"> <input id="message" class="form-control" type="text" name="message" required minlength="5">
<small class="form-text text-muted"> <small class="form-text text-muted">
{{ _("Message to display to banned user") }} {{ _("Message to display to banned user") }}