Jump to >

djblets.util.templatetags.djblets_forms

label_tag(field)[source]

Render the tag for a field’s label.

This generates labels similar to the administration UI’s own field labels, providing styling for required fields and checkboxes.

If the label is explicitly set to an empty string on the field, no label will be rendered, matching Django’s default behavior.

Parameters:field (django.forms.BoundField) – The bound field on the form to render the label for.
Returns:The resulting HTML for the label.
Return type:django.utils.safestring.SafeText

Example

{% label_for form.my_field %}
form_field_id(field)[source]

Render the ID of a field.

This will derive the field’s ID in the form and output it, for use in utility functions or custom HTML.

Parameters:field (django.forms.BoundField) – The bound field on the form.
Returns:The resulting ID as safe HTML.
Return type:django.utils.safestring.SafeText

Example

<span data-field-id="{{form.my_field|form_field_id}}"></span>
is_field_checkbox(field)[source]

Return whether or not this field is effectively a checkbox field.

A field is considered to be a checkbox field if its widget is a CheckboxInput.

Parameters:field (django.forms.BoundField) – The bound field on the form.
Returns:True if this is a checkbox field. False if not.
Return type:bool

Example

{% if field|is_field_checkbox %}
...
{% endif %}
is_checkbox_row(field)[source]

Return whether the field’s row is a checkbox-ish row.

This will return True if rendering a checkbox, radio button, or multi-select checkbox.

Parameters:field (django.forms.BoundField) – The bound field on the form.
Returns:True if this is a checkbox-ish field. False if not.
Return type:bool

Example

{% if field|is_checkbox_row %}
...
{% endif %}
form_field_has_label_first(field)[source]

Return whether a form label should be displayed before the widget.

This helps when rendering labels and widgets in the correct order. Typically, non-checkbox widgets are preceded by a label, and this lets templates determine if that should be the case for a given field.

Parameters:field (django.forms.BoundField) – The bound field on the form.
Returns:True if the label should appear before the widget. False if the widget should appear before the label.
Return type:bool

Example

{% if field|form_field_has_label_first %}
...
{% endif %}
get_fieldsets(form)[source]

Normalize and iterate over fieldsets in a form.

This will loop through the fieldsets on a given form, converting either standard Django style or legay Djblets style fieldset data into a standard form and returning it to the template.

Parameters:form (django.forms.Form) – The form containing the fieldsets.
Yields:tuple – A tuple of (fieldset_title, fieldset_info).

Example

{% for fieldset_title, fieldset in form|get_fieldsets %}
...
{% endfor %}