render_field.html 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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">
  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 mb-0">
  24. {{ field }}
  25. <label for="{{ field.id_for_label }}" class="form-check-label">
  26. {{ label }}
  27. </label>
  28. {% if field.help_text %}
  29. <span class="form-text">{{ field.help_text|safe }}</span>
  30. {% endif %}
  31. </div>
  32. {# Include a copy-to-clipboard button #}
  33. {% elif 'data-clipboard' in field.field.widget.attrs %}
  34. <div class="input-group">
  35. {{ field }}
  36. <button type="button" title="{% trans "Copy to clipboard" %}" class="btn copy-content" data-clipboard-target="#{{ field.id_for_label }}">
  37. <i class="mdi mdi-content-copy"></i>
  38. </button>
  39. </div>
  40. {# Default field rendering #}
  41. {% else %}
  42. {{ field }}
  43. {% endif %}
  44. {# Display any error messages #}
  45. {% if field.errors %}
  46. <div class="form-text text-danger">
  47. {% for error in field.errors %}{{ error }}{% if not forloop.last %}<br />{% endif %}{% endfor %}
  48. </div>
  49. {% elif field.field.required %}
  50. <div class="invalid-feedback">
  51. {% trans "This field is required" %}.
  52. </div>
  53. {% endif %}
  54. {# Help text #}
  55. {% if field.help_text and field|widget_type != 'checkboxinput' %}
  56. <span class="form-text">{{ field.help_text|safe }}</span>
  57. {% endif %}
  58. {# For bulk edit forms, include an option to nullify the field #}
  59. {% if bulk_nullable %}
  60. <div class="form-check my-1">
  61. <input type="checkbox" class="form-check-input" name="_nullify" value="{{ field.name }}" id="nullify_{{ field.id_for_label }}" />
  62. <label for="nullify_{{ field.id_for_label }}" class="form-check-label">{% trans "Set Null" %}</label>
  63. </div>
  64. {% endif %}
  65. </div>
  66. </div>