-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move form/field twig to default to be more easily extended in themes
- Loading branch information
1 parent
b991dad
commit 46a6b00
Showing
3 changed files
with
70 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
{% set originalValue = originalValue is defined ? originalValue : value %} | ||
{% set toggleableChecked = field.toggleable and (originalValue is not null and originalValue is not empty) %} | ||
{% set isDisabledToggleable = field.toggleable and not toggleableChecked %} | ||
{% set value = (value is null ? field.default : value) %} | ||
|
||
{% block field %} | ||
<div class="form-field {% if field.outerclasses is defined %} {{ field.outerclasses }}{% endif %}"> | ||
{% block contents %} | ||
<div class="form-label"> | ||
<label class="inline" {% if field.id is defined %}for="{{ field.id|e }}" {% endif %} > | ||
{% block label %} | ||
{% if field.help %} | ||
<span class="tooltip" data-asTooltip-position="w" title="{{ field.help|e|t }}">{{ field.label|default(field.name|capitalize)|t }}</span> | ||
{% else %} | ||
{{ field.label|default(field.name|capitalize)|t }} | ||
{% endif %} | ||
{{ field.validate.required in ['on', 'true', 1] ? '<span class="required">*</span>' }} | ||
{% endblock %} | ||
</label> | ||
</div> | ||
<div class="form-data" | ||
{% block global_attributes %} | ||
data-grav-field="{{ field.type }}" | ||
data-grav-disabled="{{ originalValue is null ? 'true' : 'false' }}" | ||
data-grav-default="{{ field.default|json_encode()|e('html_attr') }}" | ||
{% endblock %} | ||
> | ||
{% block group %} | ||
{% block input %} | ||
<div class="form-input-wrapper {{ field.size }} {{ field.wrapper_classes }}"> | ||
{% block prepend %}{% endblock prepend %} | ||
<input | ||
{# required attribute structures #} | ||
name="{{ (scope ~ field.name)|fieldName }}" | ||
value="{{ value|e('html_attr')|join(', ') }}" | ||
{# input attribute structures #} | ||
{% block input_attributes %} | ||
{% if field.classes is defined %}class="{{ field.classes }}" {% endif %} | ||
{% if field.id is defined %}id="{{ field.id|e }}" {% endif %} | ||
{% if field.style is defined %}style="{{ field.style|e }}" {% endif %} | ||
{% if field.disabled or isDisabledToggleable %}disabled="disabled"{% endif %} | ||
{% if field.placeholder %}placeholder="{{ field.placeholder|t }}"{% endif %} | ||
{% if field.autofocus in ['on', 'true', 1] %}autofocus="autofocus"{% endif %} | ||
{% if field.novalidate in ['on', 'true', 1] %}novalidate="novalidate"{% endif %} | ||
{% if field.readonly in ['on', 'true', 1] %}readonly="readonly"{% endif %} | ||
{% if field.autocomplete in ['on', 'off'] %}autocomplete="{{ field.autocomplete }}"{% endif %} | ||
{% if field.validate.required in ['on', 'true', 1] %}required="required"{% endif %} | ||
{% if field.validate.pattern %}pattern="{{ field.validate.pattern }}"{% endif %} | ||
{% if field.validate.message %}title="{{ field.validate.message|e|t }}" | ||
{% elseif field.title is defined %}title="{{ field.title|e|t }}" {% endif %} | ||
{% endblock %} | ||
/> | ||
{% block append %}{% endblock append %} | ||
</div> | ||
{% endblock %} | ||
{% endblock %} | ||
</div> | ||
{% endblock %} | ||
</div> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1 @@ | ||
{% set originalValue = originalValue is defined ? originalValue : value %} | ||
{% set toggleableChecked = field.toggleable and (originalValue is not null and originalValue is not empty) %} | ||
{% set isDisabledToggleable = field.toggleable and not toggleableChecked %} | ||
{% set value = (value is null ? field.default : value) %} | ||
|
||
{% block field %} | ||
<div class="form-field {% if field.outerclasses is defined %} {{ field.outerclasses }}{% endif %}"> | ||
{% block contents %} | ||
<div class="form-label"> | ||
<label class="inline" {% if field.id is defined %}for="{{ field.id|e }}" {% endif %} > | ||
{% block label %} | ||
{% if field.help %} | ||
<span class="tooltip" data-asTooltip-position="w" title="{{ field.help|e|t }}">{{ field.label|default(field.name|capitalize)|t }}</span> | ||
{% else %} | ||
{{ field.label|default(field.name|capitalize)|t }} | ||
{% endif %} | ||
{{ field.validate.required in ['on', 'true', 1] ? '<span class="required">*</span>' }} | ||
{% endblock %} | ||
</label> | ||
</div> | ||
<div class="form-data" | ||
{% block global_attributes %} | ||
data-grav-field="{{ field.type }}" | ||
data-grav-disabled="{{ originalValue is null ? 'true' : 'false' }}" | ||
data-grav-default="{{ field.default|json_encode()|e('html_attr') }}" | ||
{% endblock %} | ||
> | ||
{% block group %} | ||
{% block input %} | ||
<div class="form-input-wrapper {{ field.size }} {{ field.wrapper_classes }}"> | ||
{% block prepend %}{% endblock prepend %} | ||
<input | ||
{# required attribute structures #} | ||
name="{{ (scope ~ field.name)|fieldName }}" | ||
value="{{ value|e('html_attr')|join(', ') }}" | ||
{# input attribute structures #} | ||
{% block input_attributes %} | ||
{% if field.classes is defined %}class="{{ field.classes }}" {% endif %} | ||
{% if field.id is defined %}id="{{ field.id|e }}" {% endif %} | ||
{% if field.style is defined %}style="{{ field.style|e }}" {% endif %} | ||
{% if field.disabled or isDisabledToggleable %}disabled="disabled"{% endif %} | ||
{% if field.placeholder %}placeholder="{{ field.placeholder|t }}"{% endif %} | ||
{% if field.autofocus in ['on', 'true', 1] %}autofocus="autofocus"{% endif %} | ||
{% if field.novalidate in ['on', 'true', 1] %}novalidate="novalidate"{% endif %} | ||
{% if field.readonly in ['on', 'true', 1] %}readonly="readonly"{% endif %} | ||
{% if field.autocomplete in ['on', 'off'] %}autocomplete="{{ field.autocomplete }}"{% endif %} | ||
{% if field.validate.required in ['on', 'true', 1] %}required="required"{% endif %} | ||
{% if field.validate.pattern %}pattern="{{ field.validate.pattern }}"{% endif %} | ||
{% if field.validate.message %}title="{{ field.validate.message|e|t }}" | ||
{% elseif field.title is defined %}title="{{ field.title|e|t }}" {% endif %} | ||
{% endblock %} | ||
/> | ||
{% block append %}{% endblock append %} | ||
</div> | ||
{% endblock %} | ||
{% endblock %} | ||
</div> | ||
{% endblock %} | ||
</div> | ||
{% endblock %} | ||
{% extends "forms/default/field.html.twig" %} |