Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement floating labels for supported widgets #23

Merged
merged 3 commits into from
Mar 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/forms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,14 @@ Bootstrap 5 offers Input groups to combine fields and add-ons (both before and a

Note: input-group needs has-validation
https://github.com/twbs/bootstrap/blob/6b3254536bac263c39e3a536c3c13945210d91b2/site/content/docs/5.0/migration.md

Floating labels
---------------

Reference: https://getbootstrap.com/docs/5.0/forms/floating-labels/

This behavior can be triggere dby setting `layout="floating"`.

Floating labels are supported for widgets that can use `form-control`. An exception is `FileInput` and its descendants, those labels cannot be floating.

Setting `layout="floating"` has no effect on widgets that are not supported.
22 changes: 11 additions & 11 deletions example/templates/app/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
<div class="container">
<h1>{% block title %}(no title){% endblock %}</h1>

<p>
<a href="{% url 'home' %}">home</a>
<a href="{% url 'formset_default' %}">formset</a>
<a href="{% url 'form_default' %}">form</a>
<a href="{% url 'form_by_field' %}">form_by_field</a>
<a href="{% url 'form_horizontal' %}">form_horizontal</a>
<a href="{% url 'form_inline' %}">form_inline</a>
<a href="{% url 'form_with_files' %}">form_with_files</a>
<a href="{% url 'pagination' %}">pagination</a>
<a href="{% url 'misc' %}">miscellaneous</a>
</p>
<ul class="nav nav-pills">
<li class="nav-item"><a class="nav-link" href="{% url 'home' %}">home</a></li>
<li class="nav-item"><a class="nav-link" href="{% url 'formset_default' %}">formset</a></li>
<li class="nav-item"><a class="nav-link" href="{% url 'form_default' %}">form</a></li>
<li class="nav-item"><a class="nav-link" href="{% url 'form_by_field' %}">form_by_field</a></li>
<li class="nav-item"><a class="nav-link" href="{% url 'form_horizontal' %}">form_horizontal</a></li>
<li class="nav-item"><a class="nav-link" href="{% url 'form_inline' %}">form_inline</a></li>
<li class="nav-item"><a class="nav-link" href="{% url 'form_with_files' %}">form_with_files</a></li>
<li class="nav-item"><a class="nav-link" href="{% url 'pagination' %}">pagination</a></li>
<li class="nav-item"><a class="nav-link" href="{% url 'misc' %}">miscellaneous</a></li>
</ul>

{% autoescape off %}{% bootstrap_messages %}{% endautoescape %}

Expand Down
2 changes: 1 addition & 1 deletion example/templates/app/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

{% block content %}

<form role="form" method="post">
<form method="post">
{% csrf_token %}
{% bootstrap_form form %}
{% buttons submit='OK' reset="Cancel" %}{% endbuttons %}
Expand Down
2 changes: 1 addition & 1 deletion example/templates/app/form_with_files.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

{% block content %}

<form role="form" method="post" enctype="multipart/form-data" {% if layout != 'vertical' %}class="form-{{ layout }}"{% endif %}>
<form method="post" enctype="multipart/form-data">
{% csrf_token %}
{% bootstrap_form form layout=layout %}
{% buttons submit='OK' reset="Cancel" %}{% endbuttons %}
Expand Down
Loading