Skip to content

Commit

Permalink
Merge pull request #2261 from mccarthysean/form-checklists-more-compa…
Browse files Browse the repository at this point in the history
…ct-with-Bootstrap-4-standard-help-text

Bootstrap 4 form checklists more compact and standard
  • Loading branch information
mrjoes authored Jun 22, 2022
2 parents a31d1e5 + c2880bb commit 1df60d8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ env
*.egg
.eggs
.tox/
.env
9 changes: 7 additions & 2 deletions examples/forms-files-images/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class User(db.Model):
city = db.Column(db.Unicode(128))
country = db.Column(db.Unicode(128))
notes = db.Column(db.UnicodeText)
is_admin = db.Column(db.Boolean, default=False)


class Page(db.Model):
Expand Down Expand Up @@ -170,7 +171,7 @@ class UserView(sqla.ModelView):
"""
form_create_rules = [
# Header and four fields. Email field will go above phone field.
rules.FieldSet(('first_name', 'last_name', 'email', 'phone'), 'Personal'),
rules.FieldSet(('first_name', 'last_name', 'email', 'phone', 'is_admin'), 'Personal'),
# Separate header and few fields
rules.Header('Location'),
rules.Field('city'),
Expand All @@ -186,6 +187,10 @@ class UserView(sqla.ModelView):
create_template = 'create_user.html'
edit_template = 'edit_user.html'

column_descriptions = {
"is_admin": "Is this an admin user?",
}


# Flask views
@app.route('/')
Expand Down Expand Up @@ -290,6 +295,6 @@ def build_sample_db():
database_path = op.join(app_dir, app.config['DATABASE_FILE'])
if not os.path.exists(database_path):
build_sample_db()

# Start app
app.run(debug=True)
10 changes: 6 additions & 4 deletions flask_admin/templates/bootstrap4/admin/lib.html
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
{% set prepend = kwargs.pop('prepend', None) %}
{% set append = kwargs.pop('append', None) %}
<div class="form-group {{ kwargs.get('column_class', '') }}">
<label for="{{ field.id }}" class="control-label" {% if field.widget.input_type == 'checkbox' %}style="display: block"{% endif %}>{{ field.label.text }}
<label for="{{ field.id }}" class="control-label" {% if field.widget.input_type == 'checkbox' %}style="display: block; margin-bottom: 0"{% endif %}>{{ field.label.text }}
{% if h.is_required_form_field(field) %}
<strong style="color: red">&#42;</strong>
{%- else -%}
Expand All @@ -136,7 +136,7 @@
{%- endif -%}
{% endif %}
{% if field.widget.input_type == 'checkbox' %}
{% set _class = kwargs.setdefault('class', 'form-control-lg') %}
{% set _class = kwargs.setdefault('class', '') %}
{% elif field.widget.input_type == 'file' %}
{% set _class = kwargs.setdefault('class', 'form-control-file') %}
{% else %}
Expand All @@ -151,14 +151,16 @@
{%- endif -%}
{% if direct_error %}
<div class="invalid-feedback">
<ul class="help-block">
<ul class="form-text text-muted" {% if field.widget.input_type == 'checkbox' %}style="margin-top: 0"{% endif %}>
{% for e in field.errors if e is string %}
<li>{{ e }}</li>
{% endfor %}
</ul>
</div>
{% elif field.description %}
<div class="help-block">{{ field.description|safe }}</div>
<small class="form-text text-muted" {% if field.widget.input_type == 'checkbox' %}style="margin-top: 0"{% endif %}>
{{ field.description|safe }}
</small>
{% endif %}
{% if prepend or append %}
</div>
Expand Down

0 comments on commit 1df60d8

Please sign in to comment.