Show descriptions and optional fields

This commit is contained in:
Kevin Chung
2020-08-18 14:11:04 -04:00
parent 681a86b15c
commit 1eaf450cdb
6 changed files with 79 additions and 4 deletions

View File

@@ -25,7 +25,16 @@ def RegistrationForm(*args, **kwargs):
new_fields = UserFields.query.all()
for field in new_fields:
setattr(_RegistrationForm, f"fields[{field.id}]", StringField(field.name))
validators = []
if field.required:
validators.append(InputRequired())
setattr(
_RegistrationForm,
f"fields[{field.id}]",
StringField(
field.name, description=field.description, validators=validators
),
)
return _RegistrationForm(*args, **kwargs)

View File

@@ -42,7 +42,17 @@ def SettingsForm(*args, **kwargs):
new_fields = UserFields.query.filter_by(editable=True).all()
for field in new_fields:
setattr(_SettingsForm, f"fields[{field.id}]", StringField(field.name))
validators = []
if field.required:
validators.append(InputRequired())
setattr(
_SettingsForm,
f"fields[{field.id}]",
StringField(
field.name, description=field.description, validators=validators
),
)
return _SettingsForm(*args, **kwargs)

View File

@@ -91,7 +91,17 @@ def UserEditForm(*args, **kwargs):
new_fields = UserFields.query.all()
for field in new_fields:
setattr(_UserEditForm, f"fields[{field.id}]", StringField(field.name))
validators = []
if field.required:
validators.append(InputRequired())
setattr(
_UserEditForm,
f"fields[{field.id}]",
StringField(
field.name, description=field.description, validators=validators
),
)
return _UserEditForm(*args, **kwargs)
@@ -113,6 +123,16 @@ def UserCreateForm(*args, **kwargs):
new_fields = UserFields.query.all()
for field in new_fields:
setattr(_UserCreateForm, f"fields[{field.id}]", StringField(field.name))
validators = []
if field.required:
validators.append(InputRequired())
setattr(
_UserCreateForm,
f"fields[{field.id}]",
StringField(
field.name, description=field.description, validators=validators
),
)
return _UserCreateForm(*args, **kwargs)

View File

@@ -14,21 +14,32 @@
</div>
<div class="form-group">
{{ form.website.label }}
<small class="float-right text-muted align-text-bottom">Optional</small>
{{ form.website(class="form-control") }}
</div>
<div class="form-group">
{{ form.affiliation.label }}
<small class="float-right text-muted align-text-bottom">Optional</small>
{{ form.affiliation(class="form-control") }}
</div>
<div class="form-group">
{{ form.country.label }}
<small class="float-right text-muted align-text-bottom">Optional</small>
{{ form.country(class="form-control custom-select") }}
</div>
{% for k, v in form.extra %}
<div class="form-group">
<b>{{ v.label }}</b>
{% if v.flags.required is false %}
<small class="float-right text-muted align-text-bottom">Optional</small>
{% endif %}
{{ v(class="form-control") }}
{% if v.description %}
<small class="form-text text-muted">
{{ v.description }}
</small>
{% endif %}
</div>
{% endfor %}

View File

@@ -28,7 +28,15 @@
{% for k, v in form.extra %}
<div class="form-group">
<b>{{ v.label }}</b>
{% if v.flags.required is false %}
<small class="float-right text-muted align-text-bottom">Optional</small>
{% endif %}
{{ v(class="form-control") }}
{% if v.description %}
<small class="form-text text-muted">
{{ v.description }}
</small>
{% endif %}
</div>
{% endfor %}

View File

@@ -27,21 +27,38 @@
<div class="form-group">
<b>{{ form.name.label }}</b>
{{ form.name(class="form-control", value=name) }}
<small class="form-text text-muted">
Your username on the site
</small>
</div>
<div class="form-group">
<b>{{ form.email.label }}</b>
{{ form.email(class="form-control", value=email) }}
<small class="form-text text-muted">
Never shown to the public
</small>
</div>
<div class="form-group">
<b>{{ form.password.label }}</b>
{{ form.password(class="form-control", value=password) }}
<small class="form-text text-muted">
Password used to log into your account
</small>
</div>
{{ form.nonce() }}
{% for k, v in form.extra %}
<div class="form-group">
<b>{{ v.label }}</b>
{% if v.flags.required is false %}
<small class="float-right text-muted align-text-bottom">Optional</small>
{% endif %}
{{ v(class="form-control") }}
{% if v.description %}
<small class="form-text text-muted">
{{ v.description }}
</small>
{% endif %}
</div>
{% endfor %}