Skip to content

Adding a documentation page about Bootstrap 4 form theme #9351

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

Closed
wants to merge 9 commits into from

Conversation

Nyholm
Copy link
Member

@Nyholm Nyholm commented Feb 26, 2018

The Boostrap 4 theme has some "special" feature that we should mention.

  • I wanted to give the user a copy-paste get started template.
  • I mention WCAG2.0 because we should be proud of that and make users aware of it
  • The special classes in "custom forms" are not boostrap classes. They are feature flags in the Symfony boostrap 4 theme.
  • The half "labels and erros" is copied from the form_custimazation.rst.

Copy link
Member

@javiereguiluz javiereguiluz left a comment

Choose a reason for hiding this comment

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

I like this a lot. Thanks for contributing it. However, I was thinking of making some changes in the intro of the article to explain things more in detail:

Original

An example how to use the Boostrap 4 theme might look like this. You could of course
use any sources for the Boostrap CSS and JavaScript.

.. code-block:: html+twig

    {% form_theme form 'bootstrap_4_layout.html.twig' %}

    {% block head %}
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
        <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
    {% endblock head %}

    {% block body %}
      <h1>Here is my form:</h1>
      {{ form(form) }}
    {% endblock body %}

Proposal

Symfony provides several ways of integrating Bootstrap into your application. The
most straightforward way is to just add the required ``<link>`` and ``<script>``
elements in your templates (usually you only include them in the main layout
template which other templates extend from):

.. code-block:: html+twig

    {# templates/base.html.twig #}

    {# beware that the blocks in your template may be named different #}
    {% block head_css %}
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
    {% endblock %}
    {% block head_js %}
        <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
    {% endblock head %}

If your application uses modern front-end practices, it's better to use
:ref:`Webpack Encore </frontend>` and follow :ref:`this tutorial </frontend/encore/bootstrap>`
to import Bootstrap's sources into your SCSS and JavaScript files.

The next step is to configure the Symfony application to use Bootstrap 4 styles
when rendering forms. If you want to apply them to all forms, define this
configuration:

.. code-block:: yaml
    
    # config/packages/twig.yaml
    twig:
        # ...
        form_themes: ['bootstrap_4_layout.html.twig']

If you prefer to apply the Bootstrap styles on a form to form basis, include the
``form_theme`` tag in the templates where those forms are used:

.. code-block:: twig

    {# ... #}
    {# this tag only applies to the forms defined in this template #}
    {% form_theme form 'bootstrap_4_layout.html.twig' %}

    {% block body %}
        <h1>User Sign Up:</h1>
        {{ form(form) }}
    {% endblock body %}

@xabbuh
Copy link
Member

xabbuh commented Feb 27, 2018

Do we really need a full article for this theme? Couldn't this be integrated into the existing page where we list all the available form themes?

@javiereguiluz
Copy link
Member

The thing is that Bootstrap is extremely special and popular. Fun fact: this article published on symfony.com blog in 2014 is still our most popular blog post ever by an infinite difference: https://symfony.com/blog/new-in-symfony-2-6-bootstrap-form-theme Bootstrap is just incredibly popular, so I like the idea of a short and practical guide for it (and not for other frameworks).

@Nyholm
Copy link
Member Author

Nyholm commented Feb 27, 2018

Thank you for the feedback and reviews.

I've considered to make it as a part as an existing page. But it was too many things that were special with bootstrap 4. Also this symfony/symfony#26331 will be a special symfony/boostrap feature.

@Nyholm
Copy link
Member Author

Nyholm commented Feb 28, 2018

@weaverryan Do you have any input on this PR?

@xabbuh xabbuh added this to the 3.4 milestone Mar 4, 2018

{# beware that the blocks in your template may be named different #}
{% block head_css %}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure if we really should include this code example here. It will become outdated really fast and people will still continue to copy and paste it. What about linking to the Bootstrap getting started docs instead?

when rendering forms. If you want to apply them to all forms, define this
configuration:

.. code-block:: yaml
Copy link
Member

Choose a reason for hiding this comment

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

We should best add a configuration block containing the config for the PHP and XML formats too.

Accessibility
-------------

The Bootstrap 4 framework has done a good job making in accessible for function
Copy link
Member

Choose a reason for hiding this comment

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

[...] making it [...]?

``form_label()`` for a checkbox/radio field doesn't show anything. Due to Bootstrap
internals, the label is already shown by ``form_widget()``.

You may also note that the form errors is rendered **inside** the ``<label>``. This
Copy link
Member

Choose a reason for hiding this comment

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

are

internals, the label is already shown by ``form_widget()``.

You may also note that the form errors is rendered **inside** the ``<label>``. This
is done to make sure there is a strong connection between the error and in the
Copy link
Member

Choose a reason for hiding this comment

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

[...] and in the [...]

@@ -127,6 +127,10 @@ fragment needed to render every part of a form:
calling ``form_label()`` for a checkbox/radio field doesn't show anything.
Due to Bootstrap internals, the label is already shown by ``form_widget()``.

.. tip::

Read more about :doc:`Bootstrap 4 form theme </form/bootstrap4>`.
Copy link
Member

Choose a reason for hiding this comment

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

[...] about the Bootstrap [...]?

@Nyholm
Copy link
Member Author

Nyholm commented Mar 4, 2018

Thank you for the review. I've updated accordingly

Copy link
Member

@javiereguiluz javiereguiluz left a comment

Choose a reason for hiding this comment

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

This is looking really good. Thanks for this Tobias.

-------------

The Bootstrap 4 framework has done a good job making it accessible for function
variations like impaired vision and cognitive ability. Symfony has taken this one
Copy link
Member

Choose a reason for hiding this comment

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

Just asking: does this term sounds good to you? -> function variations Should it be functional variations or even functional diversity?

Copy link
Member Author

Choose a reason for hiding this comment

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

Im not sure. It is the perfect word in Swedish. We may need a native English speaker.

My intent is to not have the word "disabilities" or anything that could be connected to a negative tone.


The Bootstrap 4 framework has done a good job making it accessible for function
variations like impaired vision and cognitive ability. Symfony has taken this one
step further to make sure the form theme complies with the `WCAG2.0 standard`_.
Copy link
Member

Choose a reason for hiding this comment

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

WCAG2.0 standard -> WCAG 2.0 standard

-----------------

When you use the Bootstrap form themes and render the fields manually, calling
``form_label()`` for a checkbox/radio field doesn't show anything. Due to Bootstrap
Copy link
Member

Choose a reason for hiding this comment

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

doesn't show anything -> doesn't render anything ? (and later ... already shown by -> already rendered by ?)

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you

``form_label()`` for a checkbox/radio field doesn't show anything. Due to Bootstrap
internals, the label is already shown by ``form_widget()``.

You may also note that the form errors are rendered **inside** the ``<label>``. This
Copy link
Member

Choose a reason for hiding this comment

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

We could remove this -> You may also note that the ... This is done to ... to make it more concise:

Form errors are rendered **inside** the ``<label>`` element to make sure there
is a strong connection between the error and its ``<input>``, as required by the
`WCAG2.0 standard`_.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks!

@javiereguiluz
Copy link
Member

This is finally merged! Thanks Tobias for such a nice contribution.

@Nyholm Nyholm deleted the bootstrap4 branch March 13, 2018 09:45
@Nyholm
Copy link
Member Author

Nyholm commented Mar 13, 2018

Awesome. Thanks

@javiereguiluz
Copy link
Member

javiereguiluz commented Mar 13, 2018

My incompetence is also awesome 😭 I should have merged this into 3.4 instead of master. I'm going to try to fix that.

Update: I finally merged this on 3.4 branch too: https://github.com/symfony/symfony-docs/commits/3.4

@Nyholm Nyholm restored the bootstrap4 branch March 13, 2018 09:54
javiereguiluz added a commit to javiereguiluz/symfony-docs that referenced this pull request Mar 13, 2018
… theme (Nyholm)

This PR was squashed before being merged into the master branch (closes symfony#9351).

Discussion
----------

Adding a documentation page about Bootstrap 4 form theme

The Boostrap 4 theme has some "special" feature that we should mention.

* I wanted to give the user a copy-paste get started template.
* I mention WCAG2.0 because we should be proud of that and make users aware of it
* The special classes in "custom forms" are not boostrap classes. They are feature flags in the Symfony boostrap 4 theme.
* The half "labels and erros"  is copied from the `form_custimazation.rst`.

Commits
-------

696a366 Adding a documentation page about Bootstrap 4 form theme
@Nyholm Nyholm deleted the bootstrap4 branch March 13, 2018 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants