Skip to content

Commit

Permalink
Move form/field twig to default to be more easily extended in themes
Browse files Browse the repository at this point in the history
  • Loading branch information
flaviocopes committed May 12, 2016
1 parent b991dad commit 46a6b00
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 63 deletions.
12 changes: 9 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# v1.3.0-beta.5
## 05/12/2016

1. [](#improved)
* Moved form/field.html.twig file to the default folder, to be more easily extended in themes

# v1.3.0-beta.4
## 05/04/2016

1. [](#new)
* Added support for `prepend` and `append` field attributes for Text input

# v1.3.0-beta.3
## 05/03/2016

Expand Down Expand Up @@ -89,15 +95,15 @@
1. [](#bugfix)
* Fix captcha validation
* Fix issue where Form was unsetting valid page

# v1.0.2
## 12/01/2015

1. [](#bugfix)
* Fixed merge of defaults settings
* Support for arrays in `data.txt.twig`
* Fixed blueprint for admin

# v1.0.1
## 12/01/2015

Expand Down
60 changes: 60 additions & 0 deletions templates/forms/default/field.html.twig
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 %}
61 changes: 1 addition & 60 deletions templates/forms/field.html.twig
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" %}

0 comments on commit 46a6b00

Please sign in to comment.