New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] [Form] Added support for Bootstrap 4 forms #16290
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
{% use "bootstrap_4_layout.html.twig" %} | ||
|
||
{# Labels #} | ||
|
||
{% block form_label -%} | ||
{% if label is same as(false) %} | ||
<div class="{{ block('form_label_class') }}"></div> | ||
{% else %} | ||
{% set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' ' ~ block('form_label_class'))|trim}) %} | ||
{{- parent() -}} | ||
{% endif %} | ||
{%- endblock form_label %} | ||
|
||
{% block form_label_class -%} | ||
col-sm-2 | ||
{%- endblock form_label_class %} | ||
|
||
{# Rows #} | ||
|
||
{% block form_row -%} | ||
<div class="form-group row{% if (not compound or force_error|default(false)) and not valid %} has-error{% endif %}"> | ||
{{ form_label(form) }} | ||
<div class="{{ block('form_group_class') }}"> | ||
{{ form_widget(form) }} | ||
{{ form_errors(form) }} | ||
</div> | ||
</div> | ||
{%- endblock form_row %} | ||
|
||
{% block checkbox_row -%} | ||
{{- block('checkbox_radio_row') -}} | ||
{%- endblock checkbox_row %} | ||
|
||
{% block radio_row -%} | ||
{{- block('checkbox_radio_row') -}} | ||
{%- endblock radio_row %} | ||
|
||
{% block checkbox_radio_row -%} | ||
<div class="form-group row{% if not valid %} has-error{% endif %}"> | ||
<div class="{{ block('form_label_class') }}"></div> | ||
<div class="{{ block('form_group_class') }}"> | ||
{{ form_widget(form) }} | ||
{{ form_errors(form) }} | ||
</div> | ||
</div> | ||
{%- endblock checkbox_radio_row %} | ||
|
||
{% block submit_row -%} | ||
<div class="form-group row"> | ||
<div class="{{ block('form_label_class') }}"></div> | ||
<div class="{{ block('form_group_class') }}"> | ||
{{ form_widget(form) }} | ||
</div> | ||
</div> | ||
{% endblock submit_row %} | ||
|
||
{% block form_group_class -%} | ||
col-sm-10 | ||
{%- endblock form_group_class %} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,240 @@ | ||
{% use "form_div_layout.html.twig" %} | ||
|
||
{# Widgets #} | ||
|
||
{% block form_widget_simple -%} | ||
{% if type is not defined or 'file' != type %} | ||
{%- set attr = attr|merge({class: (attr.class|default('') ~ ' form-control')|trim}) -%} | ||
{% endif %} | ||
{{- parent() -}} | ||
{%- endblock form_widget_simple %} | ||
|
||
{% block textarea_widget -%} | ||
{% set attr = attr|merge({class: (attr.class|default('') ~ ' form-control')|trim}) %} | ||
{{- parent() -}} | ||
{%- endblock textarea_widget %} | ||
|
||
{% block button_widget -%} | ||
{% set attr = attr|merge({class: (attr.class|default('btn-default') ~ ' btn')|trim}) %} | ||
{{- parent() -}} | ||
{%- endblock %} | ||
|
||
{% block money_widget -%} | ||
<div class="input-group"> | ||
{% set prepend = '{{' == money_pattern[0:2] %} | ||
{% if not prepend %} | ||
<span class="input-group-addon">{{ money_pattern|replace({ '{{ widget }}':''}) }}</span> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like addons are now |
||
{% endif %} | ||
{{- block('form_widget_simple') -}} | ||
{% if prepend %} | ||
<span class="input-group-addon">{{ money_pattern|replace({ '{{ widget }}':''}) }}</span> | ||
{% endif %} | ||
</div> | ||
{%- endblock money_widget %} | ||
|
||
{% block percent_widget -%} | ||
<div class="input-group"> | ||
{{- block('form_widget_simple') -}} | ||
<span class="input-group-addon">%</span> | ||
</div> | ||
{%- endblock percent_widget %} | ||
|
||
{% block datetime_widget -%} | ||
{% if widget == 'single_text' %} | ||
{{- block('form_widget_simple') -}} | ||
{% else -%} | ||
{% set attr = attr|merge({class: (attr.class|default('') ~ ' form-inline')|trim}) -%} | ||
<div {{ block('widget_container_attributes') }}> | ||
{{- form_errors(form.date) -}} | ||
{{- form_errors(form.time) -}} | ||
{{- form_widget(form.date, { datetime: true } ) -}} | ||
{{- form_widget(form.time, { datetime: true } ) -}} | ||
</div> | ||
{%- endif %} | ||
{%- endblock datetime_widget %} | ||
|
||
{% block date_widget -%} | ||
{% if widget == 'single_text' %} | ||
{{- block('form_widget_simple') -}} | ||
{% else -%} | ||
{% set attr = attr|merge({class: (attr.class|default('') ~ ' form-inline')|trim}) -%} | ||
{% if datetime is not defined or not datetime -%} | ||
<div {{ block('widget_container_attributes') -}}> | ||
{%- endif %} | ||
{{- date_pattern|replace({ | ||
'{{ year }}': form_widget(form.year), | ||
'{{ month }}': form_widget(form.month), | ||
'{{ day }}': form_widget(form.day), | ||
})|raw -}} | ||
{% if datetime is not defined or not datetime -%} | ||
</div> | ||
{%- endif -%} | ||
{% endif %} | ||
{%- endblock date_widget %} | ||
|
||
{% block time_widget -%} | ||
{% if widget == 'single_text' %} | ||
{{- block('form_widget_simple') -}} | ||
{% else -%} | ||
{% set attr = attr|merge({class: (attr.class|default('') ~ ' form-inline')|trim}) -%} | ||
{% if datetime is not defined or false == datetime -%} | ||
<div {{ block('widget_container_attributes') -}}> | ||
{%- endif -%} | ||
{{- form_widget(form.hour) }}{% if with_minutes %}:{{ form_widget(form.minute) }}{% endif %}{% if with_seconds %}:{{ form_widget(form.second) }}{% endif %} | ||
{% if datetime is not defined or false == datetime -%} | ||
</div> | ||
{%- endif -%} | ||
{% endif %} | ||
{%- endblock time_widget %} | ||
|
||
{% block choice_widget_collapsed -%} | ||
{% set attr = attr|merge({class: (attr.class|default('') ~ ' form-control')|trim}) %} | ||
{{- parent() -}} | ||
{%- endblock %} | ||
|
||
{% block choice_widget_expanded -%} | ||
{% if '-inline' in label_attr.class|default('') -%} | ||
<div class="control-group"> | ||
{%- for child in form %} | ||
{{- form_widget(child, { | ||
parent_label_class: label_attr.class|default(''), | ||
translation_domain: choice_translation_domain, | ||
}) -}} | ||
{% endfor -%} | ||
</div> | ||
{%- else -%} | ||
<div {{ block('widget_container_attributes') }}> | ||
{%- for child in form %} | ||
{{- form_widget(child, { | ||
parent_label_class: label_attr.class|default(''), | ||
translation_domain: choice_translation_domain, | ||
}) -}} | ||
{% endfor -%} | ||
</div> | ||
{%- endif %} | ||
{%- endblock choice_widget_expanded %} | ||
|
||
{% block checkbox_widget -%} | ||
{% set parent_label_class = parent_label_class|default('') -%} | ||
{% if 'checkbox-inline' in parent_label_class %} | ||
{{- form_label(form, null, { widget: parent() }) -}} | ||
{% else -%} | ||
<div class="checkbox"> | ||
{{- form_label(form, null, { widget: parent() }) -}} | ||
</div> | ||
{%- endif %} | ||
{%- endblock checkbox_widget %} | ||
|
||
{% block radio_widget -%} | ||
{%- set parent_label_class = parent_label_class|default('') -%} | ||
{% if 'radio-inline' in parent_label_class %} | ||
{{- form_label(form, null, { widget: parent() }) -}} | ||
{% else -%} | ||
<div class="radio"> | ||
{{- form_label(form, null, { widget: parent() }) -}} | ||
</div> | ||
{%- endif %} | ||
{%- endblock radio_widget %} | ||
|
||
{# Labels #} | ||
|
||
{% block form_label -%} | ||
{%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' control-label')|trim}) -%} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bootstrap 4 has no |
||
{{- parent() -}} | ||
{%- endblock form_label %} | ||
|
||
{% block choice_label -%} | ||
{# remove the checkbox-inline and radio-inline class, it's only useful for embed labels #} | ||
{%- set label_attr = label_attr|merge({class: label_attr.class|default('')|replace({'checkbox-inline': '', 'radio-inline': ''})|trim}) -%} | ||
{{- block('form_label') -}} | ||
{% endblock %} | ||
|
||
{% block checkbox_label -%} | ||
{{- block('checkbox_radio_label') -}} | ||
{%- endblock checkbox_label %} | ||
|
||
{% block radio_label -%} | ||
{{- block('checkbox_radio_label') -}} | ||
{%- endblock radio_label %} | ||
|
||
{% block checkbox_radio_label %} | ||
{# Do not display the label if widget is not defined in order to prevent double label rendering #} | ||
{% if widget is defined %} | ||
{% if required %} | ||
{% set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' required')|trim}) %} | ||
{% endif %} | ||
{% if parent_label_class is defined %} | ||
{% set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' ' ~ parent_label_class)|trim}) %} | ||
{% endif %} | ||
{% if label is not same as(false) and label is empty %} | ||
{% set label = name|humanize %} | ||
{% endif %} | ||
<label{% for attrname, attrvalue in label_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}> | ||
{{- widget|raw }} {{ label is not same as(false) ? (translation_domain is same as(false) ? label : label|trans({}, translation_domain)) -}} | ||
</label> | ||
{% endif %} | ||
{% endblock checkbox_radio_label %} | ||
|
||
{# Rows #} | ||
|
||
{% block form_row -%} | ||
<div class="form-group{% if (not compound or force_error|default(false)) and not valid %} has-error{% endif %}"> | ||
{{- form_label(form) -}} | ||
{{- form_widget(form) -}} | ||
{{- form_errors(form) -}} | ||
</div> | ||
{%- endblock form_row %} | ||
|
||
{% block button_row -%} | ||
<div class="form-group"> | ||
{{- form_widget(form) -}} | ||
</div> | ||
{%- endblock button_row %} | ||
|
||
{% block choice_row -%} | ||
{% set force_error = true %} | ||
{{- block('form_row') }} | ||
{%- endblock choice_row %} | ||
|
||
{% block date_row -%} | ||
{% set force_error = true %} | ||
{{- block('form_row') }} | ||
{%- endblock date_row %} | ||
|
||
{% block time_row -%} | ||
{% set force_error = true %} | ||
{{- block('form_row') }} | ||
{%- endblock time_row %} | ||
|
||
{% block datetime_row -%} | ||
{% set force_error = true %} | ||
{{- block('form_row') }} | ||
{%- endblock datetime_row %} | ||
|
||
{% block checkbox_row -%} | ||
<div class="form-group{% if not valid %} has-error{% endif %}"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bootstrap4 has no |
||
{{- form_widget(form) -}} | ||
{{- form_errors(form) -}} | ||
</div> | ||
{%- endblock checkbox_row %} | ||
|
||
{% block radio_row -%} | ||
<div class="form-group{% if not valid %} has-error{% endif %}"> | ||
{{- form_widget(form) -}} | ||
{{- form_errors(form) -}} | ||
</div> | ||
{%- endblock radio_row %} | ||
|
||
{# Errors #} | ||
|
||
{% block form_errors -%} | ||
{% if errors|length > 0 -%} | ||
{% if form.parent %}<span class="help-block">{% else %}<div class="alert alert-danger">{% endif %} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bootstrap 4 has no |
||
<ul class="list-unstyled"> | ||
{%- for error in errors -%} | ||
<li>{{ error.message }}</li> | ||
{%- endfor -%} | ||
</ul> | ||
{% if form.parent %}</span>{% else %}</div>{% endif %} | ||
{%- endif %} | ||
{%- endblock form_errors %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess in case of error,
form-control-danger
style should be applied to the control itself.