Ver Fonte

#6797: Improve object edit form field layout

Matt há 4 anos atrás
pai
commit
582b69de74

+ 1 - 2
netbox/templates/dcim/device_edit.html

@@ -86,8 +86,7 @@
     </div>
 
     <div class="field-group">
-        <h5 class="text-center">Comments</h5>
-        {% render_field form.comments %}
+        {% render_field form.comments label='Comments' %}
     </div>
 
 {% endblock %}

+ 2 - 3
netbox/templates/dcim/rack_edit.html

@@ -30,7 +30,7 @@
         {% render_field form.width %}
         {% render_field form.u_height %}
         <div class="row mb-3">
-            <label class="col col-md-3 col-form-label">Outer Dimensions</label>
+            <label class="col col-md-3 col-form-label text-end">Outer Dimensions</label>
             <div class="col col-md-3">
                 {{ form.outer_width }}
                 <div class="form-text">Width</div>
@@ -53,7 +53,6 @@
         </div>
     {% endif %}
     <div class="field-group">
-        <h5 class="text-center">Comments</h5>
-        {% render_field form.comments %}
+        {% render_field form.comments label='Comments' %}
     </div>
 {% endblock %}

+ 1 - 2
netbox/templates/generic/object_edit.html

@@ -48,8 +48,7 @@
 
             {% if form.comments %}
               <div class="field-group">
-                <h5 class="text-center">Comments</h5>
-                {% render_field form.comments %}
+                {% render_field form.comments label='Comments' %}
               </div>
             {% endif %}
 

+ 6 - 0
netbox/templates/utilities/render_field.html

@@ -25,6 +25,12 @@
 
 {% elif field|widget_type == 'textarea' and not field.label %}
     <div class="row mb-3">
+        {% if label %}
+        <label class="col-sm-3 col-form-label text-end{% if field.field.required %} required{% endif %}" for="{{ field.id_for_label }}">
+            {{ label }}
+        </label>
+        {% else %}
+        {% endif %}
         <div class="col">
             {{ field }}
             {% if field.help_text %}

+ 2 - 1
netbox/utilities/templatetags/form_helpers.py

@@ -13,12 +13,13 @@ def getfield(form, fieldname):
 
 
 @register.inclusion_tag('utilities/render_field.html')
-def render_field(field, bulk_nullable=False):
+def render_field(field, bulk_nullable=False, label=None):
     """
     Render a single form field from template
     """
     return {
         'field': field,
+        'label': label,
         'bulk_nullable': bulk_nullable,
     }