Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Bootstrap4 support for Twig form theme#19648

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
hiddewie wants to merge0 commits intosymfony:masterfromhiddewie:bootstrap4
Closed

Bootstrap4 support for Twig form theme#19648

hiddewie wants to merge0 commits intosymfony:masterfromhiddewie:bootstrap4

Conversation

@hiddewie
Copy link
Contributor

@hiddewiehiddewie commentedAug 17, 2016
edited
Loading

QA
Branch?master
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#16289
LicenseMIT
Doc PR-

I have made a port of the Twig form theming code for Bootstrap 3 to the α-5 version of Bootstrap 4.

  • The (inheritance) structure of the form theming files has changed because a number of blocks are the same between BS 3 and 4. They have been migrated tobootstrap_base_layout.html.twig.
    The new tree is as follows:
bootstrap_base_layout.html.twig|-- bootstrap_3_layout.html.twig|   `-- bootstrap_3_horizontal_layout.html.twig`-- bootstrap_4_layout.html.twig    `-- bootstrap_4_horizontal_layout.html.twig
  • Any occurances of.form-horizontal have been removed from the BS 4 code.
  • Checkboxes and radio buttons have been stacked using the.form-check,.form-check-label and.form-check-input classes. There is now no distinction between checkboxes and radio buttons in the markdown.
  • All layout tests have been added and updated for BS4. The inheritance tree is as follows:
AbstractLayoutTest`-- AbstractBootstrap3LayoutTest    |-- AbstractBootstrap3HorizontalLayoutTest    `-- AbstractBootstrap4LayoutTest        `-- AbstractBootstrap4HorizontalLayoutTest

All tests pass. The classesFormExtensionBootstrap4LayoutTest andFormExtensionBootstrap4HorizontalLayoutTest have been created similarly to the BS 3 versions.

Screenshot of BS3 and 4 comparison for the same form:

1

Capenus, fsevestre, Nicofuma, manuelj555, cAstraea, yceruto, eschmar, patie, and sschueller reacted with heart emoji
@HeahDude
Copy link
Contributor

There were already#16290, but at first sight this PR adds tests and it's a good point :) thanks for working on this!

@hiddewie
Copy link
ContributorAuthor

hiddewie commentedAug 17, 2016
edited
Loading

Strange, I did not notice the link of the other PR in the original ticket. Thank you for notifying me.

@hiddewie
Copy link
ContributorAuthor

I do not understand the fail ofhttps://travis-ci.org/symfony/symfony/jobs/152929965 (class missing?).

Also, the PR#16290 does not seem up-to-date with the latest classes and HTML structure of BS 4.

@HeahDude
Copy link
Contributor

I do not understand the fail ofhttps://travis-ci.org/symfony/symfony/jobs/152929965 (class missing?).

the twig bridge now needs the form component to be >= 3.2, so you need to update itscomposer.json accordingly.

@Simperfit
Copy link
Contributor

You should consider adding an author tag on the tests class, it's alot of work and we should know who was behind this ;)

@hiddewie
Copy link
ContributorAuthor

What is the review status of this PR?

More and more use cases pop up as the Bootstrap 4 alpha becomes more stable and the Bootstrap 3 feature development had been ceased.

@fabpot
Copy link
Member

I would be more than happy to merge this PR before 3.2 end of dev (which happens by the end of the month).

@fabpot
Copy link
Member

At least, this PR needs to be rebased to get rid of the merge commit.

Simperfit reacted with thumbs up emoji

@hiddewie
Copy link
ContributorAuthor

Rebase done.

@fabpot
Copy link
Member

Any Bootstrap 4 users here to help us review this pull request?

@hiddewie
Copy link
ContributorAuthor

Maybe@lyrixx as original creator of the Bootstrap 3 files?

@lyrixx
Copy link
Member

Sorry, I never used bootstrap 4.

@mahono
Copy link

I'll have a look at it this week for a new project and will be able to give feedback by the end of the week. Hope it's not too late.

@eschmar
Copy link

One thing that i've noticed, is that for expanded fields it would be nice to use thefieldset tag with a nestedlegend instead of a label. It's the correct way and functionality likedisabling all controls within a fieldset will be enabled.

Maybe I can have a look on the weekend, but if anyone else can, please go for it!

@hiddewie
Copy link
ContributorAuthor

@eschmar I think the idea of adding a fieldset with a legend to an expanded field is nice. I will look into that.

However, the browser support for addingdisabled is in my opinion not good enough (practically no IE support) to make us of it.

@mahono
Copy link

I created some forms today using these templates. It looks pretty good to me. Works nice with current Bootstrap 4. I also like the idea of separating templates into an inheritance structure very much. To be honest I'm not enough Bootstrap 4 expert to say that everything works perfect.

@eschmar
Copy link

Thanks@hiddewie for all your efforts! I agree regarding thedisabled state.

I just migrated the forms of a smaller project and it works great! Thefieldset tag could be improved more. Now it's rendered correctly for radio boxes, but for example checkboxes get alabel tag with css class.col-form-legend. This should also be alegend.

One step even further, would be the possibility to enable thefieldset tag for entire other form types. For example, I have anAddressType. Bootstrap has support for<fieldset>.

Great work!

@hiddewie
Copy link
ContributorAuthor

@eschmar Could you post your form type with checkboxes? This should be fixed, but I cannot find your problem (any checkboxes I can try render a<fieldset> with<legend> correctly).

@eschmar
Copy link

@hiddewie Excuse me, it was an expandedEntityType:

screen shot 2016-10-11 at 13 40 06

@hiddewie
Copy link
ContributorAuthor

@eschmar

Maybe I am missing something. My entity type is also rendering correctly asfieldset +legend:

Type:
3

HTML:
capture

Horizontal layout:
2

@stof
Copy link
Member

@eschmar make sure that you don't have your own form theme overriding this partially

{# Labels #}

{% block form_label -%}
{% spaceless %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

please use whitespace control, not spaceless. Spaceless has a huge performance impact as it processing the template output with a regex and form rendering are using these blocks a lot


{% block form_row -%}
{%- if expanded is defined and expanded %}
{% set element = 'fieldset' %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

some whitespace control is missing here to ensure we don't have remaining spaces

{{- form_widget(form) -}}
{{- form_errors(form) -}}
</div>
{##}</{{ element|default('div') }} >
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

you have a useless space after the}}

{%- if expanded is defined and expanded %}
{% set element = 'fieldset' %}
{%- endif -%}
<{{ element|default('div') }} class="form-group row{% if (not compound or force_error|default(false)) and not valid %} has-danger{% endif %}">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

you have 2 spaces beforeclass while 1 is enough

{%- endblock checkbox_radio_row %}

{% block submit_row -%}
{% spaceless %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

please don't use spaceless

{% if required %}
{% set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' required')|trim}) %}
{% endif %}
{% if parent_label_class is defined %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

a bnch of whitespace-control markers are missing here

<li>{{ error.message }}</li>
{%- endfor -%}
</ul>
{% if form.parent %}</div>{% else %}</div>{% endif %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

why using a if to display the same in both cases ?


{% block form_errors -%}
{% if errors|length > 0 -%}
{% if form.parent %}<div class="form-control-feedback">{% else %}<div class="alert alert-danger">{% endif %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I would use theif only around classes rather than duplicating the whole div

{% block money_widget -%}
<div class="input-group">
{% set append = money_pattern starts with '{{' %}
{% if not append %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

missing whitespace controls here

@hiddewie
Copy link
ContributorAuthor

@stof Thank you. Done. Some of the whitespace problems were already in the existing code. They have been fixed anyway.

Copy link

@eschmareschmar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@hiddewie Sorry for the confusion. There was an issue with how i embedded the form themes. Everything is rendering correctly now!

I tried to find an easy way to mark custom form types to use thefieldset tag, however couldn't find one which didn't involve a lot of changes. An example: I have a customAddressType, where theexpanded option can not be set. But i guess that's a bit out of scope.

This PR is ready for merge, in my opinion.

{{- form_widget(form) -}}
{{- form_errors(form) -}}
</div>
{##}</{{ element|default('div') }}>
Copy link

@eschmareschmarOct 17, 2016
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Is there a reason for this (empty) comment?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

The comment was in the previous code (https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_3_horizontal_layout.html.twig#L34). It was probably put there to avoid whitespace issues (the commit I can find isa35d3d4).

eschmar reacted with thumbs up emoji
@hiddewie
Copy link
ContributorAuthor

@eschmar Thank you.

I think your request is a valid feature, but should be put into a new issue because (as you mention) it goes well out of scope of this PR/changeset.

@hiddewie
Copy link
ContributorAuthor

Ping@fabpot. Is there any progress on this feature being in the 3.2 release, or is it being pushed forward to 3.3?

@fabpot
Copy link
Member

I would be for 3.3 now. Apart from feedback from others, anything else to be done before merging?

Simperfit reacted with thumbs up emoji

@hiddewie
Copy link
ContributorAuthor

I've tried to fix all comments up to now, both code style and code content.

If there are more new or existing comments I have missed, then I will of course process them.

@alex-bacart
Copy link
Contributor

@hiddewie margin and padding styles have been changed in Bootstrap v4.0.0-alpha.5 fromm-*-* tom*-* andp-*-* top*-* (seehttps://blog.getbootstrap.com/2016/10/19/bootstrap-4-alpha-5/#utilities-overhaul)

Error list<ul> is old-styled inbootstrap_4_layout.html.twig.

@hiddewie
Copy link
ContributorAuthor

@bacart Thanks for noticing me, I've updated the Twig code.

{%- if expanded is defined and expanded -%}
{%- set element = 'fieldset' -%}
{%- endif -%}
<{{ element|default('div') }} class="form-group row{% if (not compound or force_error|default(false)) and not valid %} has-danger{% endif %}">
Copy link
Contributor

@havvghavvgDec 29, 2016
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

You should not add the grid classes (e.g.)row within the form theme. This is mixing concerns of the respective CSS classes. If you would like to make a certainform-group arow, too, you should do this using the frontend compilation (e.g. SASS mixins) and apply proper changes to the addressed form / form group / ...

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Seehttp://v4-alpha.getbootstrap.com/components/forms/#using-the-grid. How would you suggest we support horizontal forms in this form theme if not using the defaultform-group &row combination which is required in BS 4?

Copy link
Contributor

@havvghavvgJan 2, 2017
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I'm sorry, I totally missed this being the horizontal one, I was on the path it's the base one.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

No problem! Thanks for the review.

@alex-bacart
Copy link
Contributor

alex-bacart commentedJan 11, 2017
edited
Loading

@hiddewie one more notice:
{% block button_widget -%} and{% block choice_widget_collapsed -%} are not properly closed.
{%- endblock %} should be{%- endblock button_widget %} and{%- endblock choice_widget_collapsed %} respectively.

UPD: typo came frombootstrap_3_layout.html.twig.

@hiddewie
Copy link
ContributorAuthor

@bacart This has been fixed. Although in the older code not all blocks were closed with{% endblock <name> %} either (see for examplehttps://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/Twig/Resources/views/Form/foundation_5_layout.html.twig#L20).

@hiddewie
Copy link
ContributorAuthor

I don't get why GitHub closed my PR. It seems it does not recognise my force push of a rebase ontomaster...

However, the compare is not empty when I do it manually:master...hiddewie:bootstrap4

@nicolas-grekasnicolas-grekas modified the milestones:3.x,3.3Mar 24, 2017
fabpot added a commit that referenced this pull requestOct 1, 2017
…ereguiluz)This PR was merged into the 3.4 branch.Discussion----------Bootstrap4 support for Twig form theme**This PR is a followup from#19648. That PR was closed because GitHub thought my branch contained no commits after a force push...**| Q | A || --- | --- || Branch? | master || Bug fix? | no || New feature? | yes || BC breaks? | no || Deprecations? | no || Tests pass? | yes || Fixed tickets |#16289 || License | MIT || Doc PR | - |I have made a port of the Twig form theming code for Bootstrap 3 to the α-5 version of Bootstrap 4.- The (inheritance) structure of the form theming files has changed because a number of blocks are the same between BS 3 and 4. They have been migrated to `bootstrap_base_layout.html.twig`.  The new tree is as follows:```bootstrap_base_layout.html.twig|-- bootstrap_3_layout.html.twig|   `-- bootstrap_3_horizontal_layout.html.twig`-- bootstrap_4_layout.html.twig    `-- bootstrap_4_horizontal_layout.html.twig```- Any occurances of `.form-horizontal` have been removed from the BS 4 code.- Checkboxes and radio buttons have been stacked using the `.form-check`, `.form-check-label` and `.form-check-input` classes. There is now no distinction between checkboxes and radio buttons in the markdown.- All layout tests have been added and updated for BS4. The inheritance tree is as follows:```AbstractLayoutTest`-- AbstractBootstrap3LayoutTest    |-- AbstractBootstrap3HorizontalLayoutTest    `-- AbstractBootstrap4LayoutTest        `-- AbstractBootstrap4HorizontalLayoutTest```All tests pass. The classes `FormExtensionBootstrap4LayoutTest` and `FormExtensionBootstrap4HorizontalLayoutTest` have been created similarly to the BS 3 versions.- ~~The label coloring on an validation is not correct. I've made an issue (twbs/bootstrap#20535) of the problem.~~- No [custom form elements](http://v4-alpha.getbootstrap.com/components/forms/#custom-forms) have been used.- A docs PR can be created if this PR is accepted.- The new code might have to be updated if large changes occur in the BS 4 α.Screenshot of BS3 and 4 comparison for the same form:![1](https://cloud.githubusercontent.com/assets/1073881/17732594/dfcb50d6-6472-11e6-8e96-c46987809322.PNG)Commits-------f12e588 Removed unneeded wrapping quotes around a Twig key709f134 Removed unneeded wrapping quotes around a Twig key4222d54 Initial commit for Bootstrap 4 form theme, based on Bootstrap 3 form theme
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@stofstofstof requested changes

+2 more reviewers

@havvghavvghavvg left review comments

@eschmareschmareschmar left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

3.3

Development

Successfully merging this pull request may close these issues.

13 participants

@hiddewie@HeahDude@Simperfit@fabpot@lyrixx@mahono@eschmar@stof@alex-bacart@havvg@javiereguiluz@nicolas-grekas@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp