mirror of
https://github.com/aljazceru/CTFd.git
synced 2026-02-14 18:54:43 +01:00
Add rendering of boolean fields
This commit is contained in:
@@ -31,6 +31,9 @@ def build_custom_user_fields(
|
||||
for field in new_fields:
|
||||
form_field = getattr(form_cls, f"fields[{field.id}]")
|
||||
|
||||
# Add the field_type to the field so we know how to render it
|
||||
form_field.field_type = field.field_type
|
||||
|
||||
# Only include preexisting values if asked
|
||||
if include_entries is True:
|
||||
initial = user_fields.get(field.id, "")
|
||||
@@ -57,12 +60,19 @@ def attach_custom_user_fields(form_cls, **kwargs):
|
||||
if field.required:
|
||||
validators.append(InputRequired())
|
||||
|
||||
if field.field_type == "text":
|
||||
input_field = StringField(
|
||||
field.name, description=field.description, validators=validators
|
||||
)
|
||||
elif field.field_type == "boolean":
|
||||
input_field = BooleanField(
|
||||
field.name, description=field.description, validators=validators
|
||||
)
|
||||
|
||||
setattr(
|
||||
form_cls,
|
||||
f"fields[{field.id}]",
|
||||
StringField(
|
||||
field.name, description=field.description, validators=validators
|
||||
),
|
||||
input_field,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -1,23 +1,44 @@
|
||||
{% macro render_extra_fields(fields, show_labels=True, show_optionals=True, show_descriptions=True) -%}
|
||||
{% for field in fields %}
|
||||
<div class="form-group">
|
||||
{% if show_labels %}
|
||||
<b>{{ field.label }}</b>
|
||||
{% endif %}
|
||||
|
||||
{% if show_optionals %}
|
||||
{% if field.flags.required is false %}
|
||||
<small class="float-right text-muted align-text-bottom">Optional</small>
|
||||
{% if field.field_type == "text" %}
|
||||
{% if show_labels %}
|
||||
<b>{{ field.label }}</b>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
{{ field(class="form-control") }}
|
||||
{% if show_optionals %}
|
||||
{% if field.flags.required is false %}
|
||||
<small class="float-right text-muted">Optional</small>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
{% if show_descriptions %}
|
||||
{% if field.description %}
|
||||
<small class="form-text text-muted">
|
||||
{{ field.description }}
|
||||
</small>
|
||||
{{ field(class="form-control") }}
|
||||
|
||||
{% if show_descriptions %}
|
||||
{% if field.description %}
|
||||
<small class="form-text text-muted">
|
||||
{{ field.description }}
|
||||
</small>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% elif field.field_type == "boolean" %}
|
||||
<div class="form-check">
|
||||
{{ field(class="form-check-input") }}
|
||||
{{ field.label(class="form-check-label") }}
|
||||
|
||||
{% if show_optionals %}
|
||||
{% if field.flags.required is false %}
|
||||
<sup class="text-muted">Optional</sup>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% if show_descriptions %}
|
||||
{% if field.description %}
|
||||
<small class="form-text text-muted">
|
||||
{{ field.description }}
|
||||
</small>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
@@ -1,23 +1,44 @@
|
||||
{% macro render_extra_fields(fields, show_labels=True, show_optionals=True, show_descriptions=True) -%}
|
||||
{% for field in fields %}
|
||||
<div class="form-group">
|
||||
{% if show_labels %}
|
||||
<b>{{ field.label }}</b>
|
||||
{% endif %}
|
||||
|
||||
{% if show_optionals %}
|
||||
{% if field.flags.required is false %}
|
||||
<small class="float-right text-muted align-text-bottom">Optional</small>
|
||||
{% if field.field_type == "text" %}
|
||||
{% if show_labels %}
|
||||
<b>{{ field.label }}</b>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
{{ field(class="form-control") }}
|
||||
{% if show_optionals %}
|
||||
{% if field.flags.required is false %}
|
||||
<small class="float-right text-muted">Optional</small>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
{% if show_descriptions %}
|
||||
{% if field.description %}
|
||||
<small class="form-text text-muted">
|
||||
{{ field.description }}
|
||||
</small>
|
||||
{{ field(class="form-control") }}
|
||||
|
||||
{% if show_descriptions %}
|
||||
{% if field.description %}
|
||||
<small class="form-text text-muted">
|
||||
{{ field.description }}
|
||||
</small>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% elif field.field_type == "boolean" %}
|
||||
<div class="form-check">
|
||||
{{ field(class="form-check-input") }}
|
||||
{{ field.label(class="form-check-label") }}
|
||||
|
||||
{% if show_optionals %}
|
||||
{% if field.flags.required is false %}
|
||||
<sup class="text-muted">Optional</sup>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% if show_descriptions %}
|
||||
{% if field.description %}
|
||||
<small class="form-text text-muted">
|
||||
{{ field.description }}
|
||||
</small>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user