From 6effb03fcb471c9330457e9d72710428b8d7ddff Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Mon, 26 Feb 2018 19:10:05 +0100 Subject: [PATCH 1/9] Adding a documentation page about Bootstrap 4 form theme --- form/bootstrap4.rst | 66 +++++++++++++++++++++++++++++++++++++ form/form_customization.rst | 4 +++ 2 files changed, 70 insertions(+) create mode 100644 form/bootstrap4.rst diff --git a/form/bootstrap4.rst b/form/bootstrap4.rst new file mode 100644 index 00000000000..dabcfedb57c --- /dev/null +++ b/form/bootstrap4.rst @@ -0,0 +1,66 @@ +Bootstrap 4 Form Theme +====================== + +The Boostrap 4 form theme is a great way to make sure your project gets nice looking +forms without you have to do any work at all. Read about all of the features of +Bootstrap in `their documentation`_. + +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 %} + + + + + {% endblock head %} + + {% block body %} +

Here is my form:

+ {{ form(form) }} + {% endblock body %} + + +Accessibility +------------- + +The Bootstrap 4 framework has done a good job making in 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`_. + +This does not mean that your entire website automatically complies with the full +standard, but it does mean that you have come far in your work to create a design +for **all** users. + +Custom Forms +------------ + +Bootstrap 4 has a feature called "`custom forms`_". You can enable that on your +Symfony Form ``RadioType`` and ``CheckboxType`` by adding a class called ``radio-custom`` +and ``checkbox-custom`` respectively. + +.. code-block:: html+twig + + {{ form_row(form.myRadio, {attr: {class: 'radio-custom'} }) }} + {{ form_row(form.myCheckbox, {attr: {class: 'checkbox-custom'} }) }} + +Labels and Errors +----------------- + +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 +internals, the label is already shown by ``form_widget()``. + +You may also note that the form errors is rendered **inside** the ``