Skip to content

Commit

Permalink
Merge pull request #16 from hwmaier/feature/some-enhancements
Browse files Browse the repository at this point in the history
Support for cols,rows and size attribute, default type is text and label can be ommited
  • Loading branch information
flaviocopes committed Nov 12, 2015
2 parents c2f3414 + 1af4248 commit 50a6eb3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion templates/forms/default/form.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{% for field in form.fields %}
{% set value = form.value(field.name) %}
<div>
{% include "forms/fields/#{field.type}/#{field.type}.html.twig" %}
{% include "forms/fields/#{field.type|default('text')}/#{field.type|default('text')}.html.twig" %}
</div>
{% endfor %}

Expand Down
5 changes: 3 additions & 2 deletions templates/forms/field.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
<label class="inline">
{% block label %}
{% if field.help %}
<span class="tooltip" data-asTooltip-position="w" title="{{ field.help|e }}">{{ field.label }}</span>
<span class="tooltip" data-asTooltip-position="w" title="{{ field.help|e }}">{{ field.label|default(field.name|capitalize) }}</span>
{% else %}
{{ field.label }}
{{ field.label|default(field.name|capitalize) }}
{% endif %}
{{ field.validate.required in ['on', 'true', 1] ? '<span class="required">*</span>' }}
{% endblock %}
Expand Down Expand Up @@ -43,6 +43,7 @@
{% 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.size %}size="{{ field.size }}"{% 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 }}"
Expand Down
4 changes: 3 additions & 1 deletion templates/forms/fields/textarea/textarea.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{% block input %}
<div class="form-textarea-wrapper {{ field.size }}">
<textarea class="input" name="{{ (scope ~ field.name)|fieldName }}"
<textarea class="input"
{# required attribute structures #}
name="{{ (scope ~ field.name)|fieldName }}"
{# input attribute structures #}
Expand All @@ -19,6 +19,8 @@
{% 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="{% if grav.twig.twig.filters['tu'] is defined %}{{ field.validate.message|tu }}{% else %}{{ field.validate.message|t }}{% endif %}"{% endif %}
{% if field.rows is defined %}rows="{{ field.rows }}"{% endif %}
{% if field.cols is defined %}cols="{{ field.cols }}"{% endif %}
{% endblock %}
>{{ value|trim|e('html') }}</textarea>
</div>
Expand Down

0 comments on commit 50a6eb3

Please sign in to comment.