render_field.html 2.6 KB

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