Skip to content
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

[Form] Documented "Supporting Bootstrap 4 custom switches" #12464

Merged
merged 1 commit into from
Nov 9, 2019

Conversation

romaricdrigon
Copy link
Contributor

Hello,

This PR add the doc for the corresponding proposed feature, custom switch support in default form theme:

image

See the Symfony PR for implementation details.

@OskarStark OskarStark added this to the 4.4 milestone Oct 11, 2019
@OskarStark OskarStark added the Waiting Code Merge Docs for features pending to be merged label Oct 11, 2019
@OskarStark
Copy link
Contributor

OskarStark commented Oct 11, 2019

Note for the mergers: this must go into 4.4

@romaricdrigon I updated the base branch

@OskarStark OskarStark changed the base branch from master to 4.4 October 11, 2019 18:32
@romaricdrigon
Copy link
Contributor Author

Thank you!

fabpot added a commit to symfony/symfony that referenced this pull request Nov 3, 2019
…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.

![image](https://user-images.githubusercontent.com/919405/66651725-0eaa3100-ec34-11e9-8b68-94324730ac80.png)

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):
![image](https://user-images.githubusercontent.com/919405/66652982-41a1f400-ec37-11e9-813f-4b39087e89e7.png)
```php
    ->add('test', CheckboxType::class, [
        'label_attr' => [
            'class' => 'checkbox-custom',
        ],
    ])
```
Custom switch (proposed):
![image](https://user-images.githubusercontent.com/919405/66652902-1919fa00-ec37-11e9-98f3-9340b01b2335.png)
```php
    ->add('test', CheckboxType::class, [
        'label_attr' => [
            'class' => 'switch-custom',
        ],
    ])
```

Commits
-------

99f59e2 Supporting Bootstrap 4 custom switches
symfony-splitter pushed a commit to symfony/twig-bridge that referenced this pull request Nov 3, 2019
…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.

![image](https://user-images.githubusercontent.com/919405/66651725-0eaa3100-ec34-11e9-8b68-94324730ac80.png)

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):
![image](https://user-images.githubusercontent.com/919405/66652982-41a1f400-ec37-11e9-813f-4b39087e89e7.png)
```php
    ->add('test', CheckboxType::class, [
        'label_attr' => [
            'class' => 'checkbox-custom',
        ],
    ])
```
Custom switch (proposed):
![image](https://user-images.githubusercontent.com/919405/66652902-1919fa00-ec37-11e9-98f3-9340b01b2335.png)
```php
    ->add('test', CheckboxType::class, [
        'label_attr' => [
            'class' => 'switch-custom',
        ],
    ])
```

Commits
-------

99f59e262f Supporting Bootstrap 4 custom switches
@OskarStark OskarStark removed the Waiting Code Merge Docs for features pending to be merged label Nov 6, 2019
wouterj added a commit that referenced this pull request Nov 9, 2019
…hes" (romaricdrigon)

This PR was merged into the 4.4 branch.

Discussion
----------

[Form] Documented "Supporting Bootstrap 4 custom switches"

Hello,

This PR add the doc for the corresponding proposed feature, custom switch support in default form theme:

![image](https://user-images.githubusercontent.com/919405/66652902-1919fa00-ec37-11e9-98f3-9340b01b2335.png)

See the Symfony PR for implementation details.

Commits
-------

fbfeec1 Documentation for Bootstrap 4 custom switches
wouterj added a commit that referenced this pull request Nov 9, 2019
@wouterj wouterj merged commit fbfeec1 into symfony:4.4 Nov 9, 2019
@wouterj
Copy link
Member

wouterj commented Nov 9, 2019

Thanks @romaricdrigon! I love this feature :)

Fyi, I've made a few (mostly reSt syntax) minor changes in 539ec5e.

wouterj added a commit that referenced this pull request Nov 9, 2019
* 4.4:
  [#12231] Explicitly name the options that can be configured through tags
  Explain how to add `from_transport` on `messenger.message_handler` tag
  Documented the new REMOTE_ADDR option
  [#12464] Minor changes
  Add Composer installation before step 1 for Symfony Flex
  Documentation for Bootstrap 4 custom switches
@romaricdrigon romaricdrigon deleted the feat-switch branch November 10, 2019 20:05
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.

None yet

4 participants