Skip to content

Commit

Permalink
Change form layout from horizontal to vertical
Browse files Browse the repository at this point in the history
Issue #116
Fixes #103
  • Loading branch information
TomaszGasior committed Apr 29, 2021
1 parent b4abaaf commit 146df0a
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 72 deletions.
59 changes: 17 additions & 42 deletions assets/css/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -556,59 +556,34 @@ input[type="checkbox"]:focus:not(:hover) + label, input[type="radio"]:focus:not(
}


/* form widgets — special */

input.color {
max-width: 200px;
}


/* form items lists */

.form-item {
width: 100%;
}

.form-item.form-regular {
display: flex;
margin: 0.7em 0;
}
.form-item.form-regular > *:first-child {
width: 40%;
margin: 20px 0;
}
.form-item.form-regular > *:last-child {
flex: 1;
.form-item label {
display: block;
margin-bottom: 7px;
}

.form-item.form-checkbox {
margin: 0.9em 0;

.form-item-checkbox {
/* needed for inputs and fake checkboxes with position absolute */
position: relative;
}

.form-item label {
display: block;
}
.form-item.form-regular label {
margin-top: 5px;
.form-item-checkbox label {
margin-bottom: 0;
}

@media (max-width: 800px)
{
.form-item.form-regular {
flex-direction: column;
}
.form-item.form-regular > *:first-child {
width: auto;
}
.form-item.form-regular label {
margin-bottom: 0.5em;
}

.form-item.form-checkbox {
margin: 1.3em 0;
}
.form-error-message {
color: #ff0000;
margin: 7px 0 0;
font-weight: bold;
}
.form-help-message {
font-size: 0.9em;
font-style: italic;
margin: 7px 0 0;
opacity: 0.8;
}


Expand Down
16 changes: 7 additions & 9 deletions assets/css/radio-table-settings.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
/* columns UI */

.JS .radio-table-columns {
width: 80%;
margin: 1.2em auto;
}
.JS .radio-table-columns .form-item {
Expand All @@ -14,13 +13,15 @@
border: 1px solid #C2C2C2;
padding: 0.5em 1em;
box-sizing: border-box;
display: flex;
align-items: center;
}
.JS .radio-table-columns .form-item label {
margin-top: 0;
margin: 0;
}
.JS .radio-table-columns .form-item > :last-child {
text-align: right;
flex: 1;
}
.JS .radio-table-columns .form-item.hidden-column {
background: #FBFBFB;
Expand All @@ -45,23 +46,20 @@

@media (max-width: 800px)
{
.JS .radio-table-columns {
width: auto;
}
.JS .radio-table-columns .form-item.form-regular {
.JS .radio-table-columns .form-item {
flex-direction: row;
}
.JS .radio-table-columns .form-item.form-regular label {
.JS .radio-table-columns .form-item label {
margin-bottom: 0;
}
}

@media (max-width: 700px)
{
.JS .radio-table-columns .form-item.form-regular {
.JS .radio-table-columns .form-item {
flex-direction: column;
}
.JS .radio-table-columns .form-item.form-regular label {
.JS .radio-table-columns .form-item label {
margin-bottom: 0.7em;
}
.JS .radio-table-columns .form-item > :last-child {
Expand Down
3 changes: 2 additions & 1 deletion assets/js/src/RadioTableColumnsUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ export class RadioTableColumnsUI
item.buttonToggle.disabled = true;
}

let buttonsContainer = item.block.lastElementChild;
let buttonsContainer = document.createElement('div');
item.block.appendChild(buttonsContainer)
buttonsContainer.appendChild(item.buttonToggle);
buttonsContainer.appendChild(item.buttonMoveUp);
buttonsContainer.appendChild(item.buttonMoveDown);
Expand Down
20 changes: 14 additions & 6 deletions templates/common/form/custom_types.html.twig
Original file line number Diff line number Diff line change
@@ -1,30 +1,38 @@
{% block integer_unit_widget %}
{% set unit_label_id = id ~ '_unit' %}
{% set attr = attr|merge({'aria-describedby': (attr['aria-describedby'] ?? '') ~ ' ' ~ unit_label_id}) %}

{{ block('integer_widget') }}
<span class="unit-label">{{ unit_label }}</span>
{% endblock integer_unit_widget %}

<span class="unit-label" id="{{ unit_label_id }}">
{{ unit_label }}
</span>
{% endblock %}

{% block decimal_unit_widget %}
{% set attr = attr|merge({
'class': attr.class|default('') ~ ' decimal',
'step': step,
'min': step,
}) %}

{{ block('integer_unit_widget') }}
{% endblock decimal_unit_widget %}
{% endblock %}

{% block radio_table_columns_row %}
{# Do not render label for radio table columns widget. #}
{{ block('form_rows') }}
{% endblock radio_table_columns_row %}
{% endblock %}

{% block text_hints_widget %}
{% set hints_list_id = id ~ '_hints' %}
{% set attr = attr|merge({'list': hints_list_id}) %}

<datalist id="{{ hints_list_id }}">
{% for hint in hints %}
<option>{{ hint }}</option>
{% endfor %}
</datalist>

{% set attr = attr|merge({'list': hints_list_id}) %}
{{ block('form_widget') }}
{% endblock text_hints_widget %}
{% endblock %}
57 changes: 43 additions & 14 deletions templates/common/form/overwritten_types.html.twig
Original file line number Diff line number Diff line change
@@ -1,30 +1,59 @@
{% block form_row %}
<div class="form-item form-regular">
<div>{{ form_label(form) }}</div>
<div>{{ form_widget(form) }}</div>
{%- set aria_describedby = (attr['aria-describedby'] ?? '') ~ (errors|length > 0 ? ' ' ~ id ~ '_error') ~ (help ? ' ' ~ id ~ '_help') -%}

<div class="form-item">
{{ form_label(form) }}
{{ form_widget(form, {attr: {'aria-describedby': aria_describedby|trim}}) }}
{{ form_errors(form) }}
{{ form_help(form) }}
</div>
{% endblock form_row %}
{% endblock %}

{% block checkbox_row %}
<div class="form-item form-checkbox">
{{ form_widget(form) }}
{{ form_label(form) }}
{%- set aria_describedby = (attr['aria-describedby'] ?? '') ~ (errors|length > 0 ? ' ' ~ id ~ '_error') ~ (help ? ' ' ~ id ~ '_help') -%}

<div class="form-item form-item-checkbox">
<div>
{{ form_widget(form, {attr: {'aria-describedby': aria_describedby|trim}}) }}
{{ form_label(form) }}
</div>

{{ form_errors(form) }}
{{ form_help(form) }}
</div>
{% endblock checkbox_row %}
{% endblock %}

{% block radio_row %}
{{ block('checkbox_row') }}
{% endblock radio_row %}
{% block form_errors %}
{%- if errors|length > 0 -%}
<p class="form-error-message" id="{{ id }}_error">
{{ (errors|first).message }}
</p>
{%- endif -%}
{% endblock %}

{% block form_help %}
{%- if help -%}
<p class="form-help-message" id="{{ id }}_help">
{{ help_html ? field_help(form)|raw : field_help(form) }}
</p>
{%- endif -%}
{% endblock %}

{% block choice_row %}
{% if expanded %}
<fieldset>
{%- set aria_describedby = (attr['aria-describedby'] ?? '') ~ (errors|length > 0 ? ' ' ~ id ~ '_error') ~ (help ? ' ' ~ id ~ '_help') -%}

<fieldset class="form-group">
<legend class="sr-only">{{ form_label(form)|striptags }}</legend>

{% for child in form %}
{{ form_row(child) }}
{{ form_row(child, {attr: {'aria-describedby': aria_describedby|trim}}) }}
{% endfor %}

{{ form_errors(form) }}
{{ form_help(form) }}
</fieldset>
{% else %}
{{ form_row(form) }}
{% endif %}
{% endblock choice_row %}
{% endblock %}

0 comments on commit 146df0a

Please sign in to comment.