field.html.twig 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. {% set originalValue = originalValue is defined ? originalValue : value %}
  2. {% set toggleableChecked = field.toggleable and (originalValue is not null and originalValue is not empty) %}
  3. {% set isDisabledToggleable = field.toggleable and not toggleableChecked %}
  4. {% set value = (value is null ? field.default : value) %}
  5. {% set vertical = field.style == 'vertical' %}
  6. {% set field_name = (scope ~ field.name)|fieldName %}
  7. {% if field.yaml and value is iterable %}
  8. {% set value = value|toYaml %}
  9. {% endif %}
  10. {% block field %}
  11. <div class="form-field grid{% if vertical %} vertical{% endif %}{% if field.toggleable %} form-field-toggleable{% endif %} {{ field.outerclasses }} {{ field.field_classes }}">
  12. {% block contents %}
  13. <div class="form-label{% if not vertical %} block size-1-3{% endif %}">
  14. {% if field.toggleable %}
  15. <span class="checkboxes toggleable" data-grav-field="toggleable" data-grav-field-name="{{ field_name }}">
  16. <input type="checkbox"
  17. id="toggleable_{{ field.name }}"
  18. {% if toggleableChecked %}value="1"{% endif %}
  19. name="toggleable_{{ field_name }}"
  20. {% if toggleableChecked %}checked="checked"{% endif %}
  21. >
  22. <label for="toggleable_{{ field.name }}"></label>
  23. </span>
  24. {% endif %}
  25. <label{{ (field.toggleable ? ' class="toggleable" for="toggleable_' ~ field.name ~ '"')|raw }}>
  26. {% block label %}
  27. {% if field.help %}
  28. <span class="hint--bottom" data-hint="{{ field.help|tu|e('html') }}">{{ field.label|tu|raw }}</span>
  29. {% else %}
  30. {{ field.label|tu|raw }}
  31. {% endif %}
  32. {{ field.validate.required in ['on', 'true', 1] ? '<span class="required">*</span>' }}
  33. {% endblock %}
  34. </label>
  35. {% if field.sublabel %}
  36. <div class="form-sublabel">
  37. {{ field.sublabel|tu|markdown|raw }}
  38. </div>
  39. {% endif %}
  40. </div>
  41. <div class="form-data{% if not vertical %} block size-2-3{% endif %}"
  42. {% block global_attributes %}
  43. data-grav-field="{{ field.type }}"
  44. data-grav-disabled="{{ toggleableChecked }}"
  45. data-grav-default="{{ field.default|json_encode|e('html_attr') }}"
  46. {% endblock %}
  47. >
  48. {% block group %}
  49. {% block input %}
  50. <div class="form-input-wrapper {{ field.size }} {{ field.wrapper_classes }}">
  51. {% block prepend %}{% endblock prepend %}
  52. <input
  53. {# required attribute structures #}
  54. name="{{ field_name }}"
  55. value="{{ value|join(', ') }}"
  56. {% if field.key %}
  57. data-key-observe="{{ (scope ~ field_name)|fieldName }}"
  58. {% endif %}
  59. {# input attribute structures #}
  60. {% block input_attributes %}
  61. {% if field.classes is defined %}class="{{ field.classes }}" {% endif %}
  62. {% if field.id is defined %}id="{{ field.id|e }}" {% endif %}
  63. {% if field.style is defined %}style="{{ field.style|e }}" {% endif %}
  64. {% if field.disabled or isDisabledToggleable %}disabled="disabled"{% endif %}
  65. {% if field.placeholder %}placeholder="{{ field.placeholder|tu }}"{% endif %}
  66. {% if field.autofocus in ['on', 'true', 1] %}autofocus="autofocus"{% endif %}
  67. {% if field.novalidate in ['on', 'true', 1] %}novalidate="novalidate"{% endif %}
  68. {% if field.readonly in ['on', 'true', 1] %}readonly="readonly"{% endif %}
  69. {% if field.autocomplete in ['on', 'off'] %}autocomplete="{{ field.autocomplete }}"{% endif %}
  70. {% if field.validate.required in ['on', 'true', 1] %}required="required"{% endif %}
  71. {% if field.validate.pattern %}pattern="{{ field.validate.pattern }}"{% endif %}
  72. {% if field.validate.message %}title="{{ field.validate.message|e|tu }}"
  73. {% elseif field.title is defined %}title="{{ field.title|e|tu }}" {% endif %}
  74. {% endblock %}
  75. />
  76. {% block append %}{% endblock append %}
  77. </div>
  78. {% endblock %}
  79. {% endblock %}
  80. {% if field.description %}
  81. <div class="form-extra-wrapper {{ field.size }} {{ field.wrapper_classes }}">
  82. <span class="form-description">{{ field.description|tu|raw }}</span>
  83. </div>
  84. {% endif %}
  85. </div>
  86. {% endblock %}
  87. </div>
  88. {% endblock %}