render_field.html 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. {% load form_helpers %}
  2. {% load helpers %}
  3. {% load i18n %}
  4. <div class="row mb-3{% if field.errors %} has-errors{% endif %}">
  5. {# Render the field label (if any), except for checkboxes #}
  6. {% if label and not field|widget_type == 'checkboxinput' %}
  7. <div class="col-sm-3 text-lg-end">
  8. <label for="{{ field.id_for_label }}" class="col-form-label d-inline-block{% if field.field.required %} required{% endif %}">
  9. {{ label }}
  10. </label>
  11. </div>
  12. {% endif %}
  13. {# Render the field itself #}
  14. <div class="col{% if field|widget_type == 'checkboxinput' %} offset-3{% endif %}">
  15. {# Include the "regenerate" button on slug fields #}
  16. {% if field|widget_type == 'slugwidget' %}
  17. <div class="input-group">
  18. {{ field }}
  19. <button type="button" title="{% trans "Regenerate Slug" %}" class="btn reslug">
  20. <i class="mdi mdi-reload"></i>
  21. </button>
  22. </div>
  23. {# Render checkbox labels to the right of the field #}
  24. {% elif field|widget_type == 'checkboxinput' %}
  25. <div class="form-check mb-0">
  26. {{ field }}
  27. <label for="{{ field.id_for_label }}" class="form-check-label">
  28. {{ label }}
  29. </label>
  30. {% if field.help_text %}
  31. <span class="form-text">{{ field.help_text|safe }}</span>
  32. {% endif %}
  33. </div>
  34. {# Include a copy-to-clipboard button #}
  35. {% elif 'data-clipboard' in field.field.widget.attrs %}
  36. <div class="input-group">
  37. {{ field }}
  38. <button type="button" title="{% trans "Copy to clipboard" %}" class="btn copy-content" data-clipboard-target="#{{ field.id_for_label }}">
  39. <i class="mdi mdi-content-copy"></i>
  40. </button>
  41. </div>
  42. {# Default field rendering #}
  43. {% else %}
  44. {{ field }}
  45. {% endif %}
  46. {# Display any error messages #}
  47. {% if field.errors %}
  48. <div class="form-text text-danger">
  49. {% for error in field.errors %}{{ error }}{% if not forloop.last %}<br />{% endif %}{% endfor %}
  50. </div>
  51. {% endif %}
  52. {# Help text #}
  53. {% if field.help_text and field|widget_type != 'checkboxinput' %}
  54. <span class="form-text">{{ field.help_text|safe }}</span>
  55. {% endif %}
  56. {# For bulk edit forms, include an option to nullify the field #}
  57. {% if bulk_nullable %}
  58. <div class="form-check my-1">
  59. <input type="checkbox" class="form-check-input" name="_nullify" value="{{ field.name }}" id="nullify_{{ field.id_for_label }}" />
  60. <label for="nullify_{{ field.id_for_label }}" class="form-check-label">{% trans "Set Null" %}</label>
  61. </div>
  62. {% endif %}
  63. </div>
  64. </div>