diff --git a/CTFd/forms/users.py b/CTFd/forms/users.py index 9b1882a5..de13a648 100644 --- a/CTFd/forms/users.py +++ b/CTFd/forms/users.py @@ -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, ) diff --git a/CTFd/themes/admin/templates/macros/forms.html b/CTFd/themes/admin/templates/macros/forms.html index 520f0059..8c795121 100644 --- a/CTFd/themes/admin/templates/macros/forms.html +++ b/CTFd/themes/admin/templates/macros/forms.html @@ -1,23 +1,44 @@ {% macro render_extra_fields(fields, show_labels=True, show_optionals=True, show_descriptions=True) -%} {% for field in fields %}
- {% if show_labels %} - {{ field.label }} - {% endif %} - - {% if show_optionals %} - {% if field.flags.required is false %} - Optional + {% if field.field_type == "text" %} + {% if show_labels %} + {{ field.label }} {% endif %} - {% endif %} - {{ field(class="form-control") }} + {% if show_optionals %} + {% if field.flags.required is false %} + Optional + {% endif %} + {% endif %} - {% if show_descriptions %} - {% if field.description %} - - {{ field.description }} - + {{ field(class="form-control") }} + + {% if show_descriptions %} + {% if field.description %} + + {{ field.description }} + + {% endif %} + {% endif %} + {% elif field.field_type == "boolean" %} +
+ {{ field(class="form-check-input") }} + {{ field.label(class="form-check-label") }} + + {% if show_optionals %} + {% if field.flags.required is false %} + Optional + {% endif %} + {% endif %} +
+ + {% if show_descriptions %} + {% if field.description %} + + {{ field.description }} + + {% endif %} {% endif %} {% endif %}
diff --git a/CTFd/themes/core/templates/macros/forms.html b/CTFd/themes/core/templates/macros/forms.html index 520f0059..8c795121 100644 --- a/CTFd/themes/core/templates/macros/forms.html +++ b/CTFd/themes/core/templates/macros/forms.html @@ -1,23 +1,44 @@ {% macro render_extra_fields(fields, show_labels=True, show_optionals=True, show_descriptions=True) -%} {% for field in fields %}
- {% if show_labels %} - {{ field.label }} - {% endif %} - - {% if show_optionals %} - {% if field.flags.required is false %} - Optional + {% if field.field_type == "text" %} + {% if show_labels %} + {{ field.label }} {% endif %} - {% endif %} - {{ field(class="form-control") }} + {% if show_optionals %} + {% if field.flags.required is false %} + Optional + {% endif %} + {% endif %} - {% if show_descriptions %} - {% if field.description %} - - {{ field.description }} - + {{ field(class="form-control") }} + + {% if show_descriptions %} + {% if field.description %} + + {{ field.description }} + + {% endif %} + {% endif %} + {% elif field.field_type == "boolean" %} +
+ {{ field(class="form-check-input") }} + {{ field.label(class="form-check-label") }} + + {% if show_optionals %} + {% if field.flags.required is false %} + Optional + {% endif %} + {% endif %} +
+ + {% if show_descriptions %} + {% if field.description %} + + {{ field.description }} + + {% endif %} {% endif %} {% endif %}