-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Form theme: support Bootstrap 4 custom switches #33954
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
Conversation
I love this ... but I have two questions:
|
I'm seeing it as a checkbox "skin". It still behaves exactly as a checkbox, both functionality wise (for the user) and in PHP code (for the developer). So imo adding a I think the feature is not quite exclusive to Bootstrap, other framework could read that attribute and implement switches too (for instance, Foundation took a similar approach). Indeed, right Bootstrap has a better integration such as form help (which is displayed as a normal div for Foundation), invalid form fields, etc., but we don't break any other form themes or prevent them to use it too. |
a57d479
to
c36bc0e
Compare
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.
@romaricdrigon your comment made me change my mind. Although we're on the edge here, it's true that this is just "a skin", even if the perceived behavior changes. Thanks!
src/Symfony/Bridge/Twig/CHANGELOG.md
Outdated
@@ -10,6 +10,8 @@ CHANGELOG | |||
* the `LintCommand` lints all the templates stored in all configured Twig paths if none argument is provided | |||
* deprecated accepting STDIN implicitly when using the `lint:twig` command, use `lint:twig -` (append a dash) instead to make it explicit. | |||
* added `--show-deprecations` option to the `lint:twig` command | |||
* added support for Bootstrap4 switches, use `switch-custom` as `label_attr` in a `CheckboxType` | |||
|
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.
the additional blank line should be removed
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.
Right, that's fixed
c36bc0e
to
99f59e2
Compare
Thank you @romaricdrigon. |
…icdrigon) This PR was merged into the 4.4 branch. Discussion ---------- Form theme: support Bootstrap 4 custom switches | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | / | License | MIT | Doc PR | symfony/symfony-docs#12464 Hello, At the moment, Symfony form theme supports [custom checkboxes](https://getbootstrap.com/docs/4.3/components/forms/#checkboxes) through an extra class in `label_attr`. Bootstrap4 introduced also [custom switches](https://getbootstrap.com/docs/4.3/components/forms/#switches), which has exactly the same HTML markup, but use a different class. This PR slightly modify `bootstrap_4_layout` to handle it.  Some reasons why I think supporting those have its place in Symfony: - those are getting common in UI right now, it is a common use case - it is complementary to normal checkboxes, and works the same way: required attribute, validation error, and so on are supported immediately - implementing it yourself in your form theme is actually tricky, because of the way checkbox are handled (ie., `form_label` called inside `form_widget` with a `{ widget: parent() }`). You have to overwrite the whole fragment, otherwise you get an infinite recursion. Finally, some screenshots and code examples. Custom checkbox (as at the moment):  ```php ->add('test', CheckboxType::class, [ 'label_attr' => [ 'class' => 'checkbox-custom', ], ]) ``` Custom switch (proposed):  ```php ->add('test', CheckboxType::class, [ 'label_attr' => [ 'class' => 'switch-custom', ], ]) ``` Commits ------- 99f59e2 Supporting Bootstrap 4 custom switches
This PR was merged into the 4.4 branch. Discussion ---------- [TwigBridge] Fix switch-custom changelog entry | Q | A | ------------- | --- | Branch? | 4.4 <!-- see below --> | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Relates to #33954 | License | MIT | Doc PR | N/A As it doesn't really mention `switch-custom` is a css class. Commits ------- b03b7f4 [TwigBridge] Fix switch-custom changelog entry
Hello,
At the moment, Symfony form theme supports custom checkboxes through an extra class in
label_attr
.Bootstrap4 introduced also custom switches, which has exactly the same HTML markup, but use a different class. This PR slightly modify
bootstrap_4_layout
to handle it.Some reasons why I think supporting those have its place in Symfony:
form_label
called insideform_widget
with a{ widget: parent() }
). You have to overwrite the whole fragment, otherwise you get an infinite recursion.Finally, some screenshots and code examples.
Custom checkbox (as at the moment):

Custom switch (proposed):
