Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Form] The html5 option doesn't work as expected for DateTime types #16600

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
javiereguiluz opened this issue Mar 14, 2022 · 6 comments
Closed
Labels

Comments

@javiereguiluz
Copy link
Member

In this page: https://symfony.com/doc/4.4/reference/forms/types/date.html#html5

We say that adding ['html5' => true] is enough to display a native browser widget to pick dates.

I can't make it work. I need to use ['html5' => true, 'widget' => 'single_text'] to render those native widgets.

Am I doing something wrong or should we update the docs? Thanks!

@carsonbot carsonbot added the Form label Mar 14, 2022
@htmlshaman1
Copy link

htmlshaman1 commented Mar 15, 2022

Can confirm, setting html5 to true is not enough to show the html5 widget for me either.

I had to have 'single_text' to display the the html5 widget, which worked without html5 set to true.

https://github.com/symfony/symfony/blob/4.4/src/Symfony/Component/Form/Extension/Core/Type/DateType.php#L192

And when I look at the options passed to DateType, it defaults to html5 = true without me setting it, therefore 'single_text' is enough.

@mdoutreluingne
Copy link
Contributor

mdoutreluingne commented Mar 28, 2022

I also confirm that I need to use ['html5' => true, 'widget' => 'single_text'] or just ['widget' => 'single_text']
(because html5 is true by default) for the types DateType, DateTimeType, TimeType to be considered as an html5 field, to then render the native widget.

I think we need to update the documentation because the wording is incomplete. For the 3 types that I have stated, it should be indicated that it is necessary to use ['html5' => true, 'widget' => 'single_text'] to render those native widgets.

What do you think ? If you affirm I can create a PR.

@xabbuh
Copy link
Member

xabbuh commented Apr 1, 2022

@mdoutreluingne Yes, that looks correct to me.

@javiereguiluz
Copy link
Member Author

@xabbuh do you think we could improve the code of these Form types to simplify all this? Maybe using widget => 'html5' would be enough to say that you want to render the HTML5 native date widget of browsers?

@xabbuh
Copy link
Member

xabbuh commented Apr 1, 2022

@javiereguiluz That sounds like a good idea to me.

nicolas-grekas added a commit to symfony/symfony that referenced this issue Apr 19, 2023
…f date/time form types (MrYamous, nicolas-grekas)

This PR was merged into the 6.3 branch.

Discussion
----------

[Form] Deprecate not configuring the "widget" option of date/time form types

| Q             | A
| ------------- | ---
| Branch?       | 6.3
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | Related to a suggestion made on symfony/symfony-docs#16600
| License       | MIT
| Doc PR        | TODO

This PR proposes to change the default value of the `widget` option of date/time form types to `single_text`, so that the corresponding input fields are rendered using native HTML5 widgets by default.

It does so by deprecating *not* setting the `widget` option, so that we can change the default in Symfony 7.

Commits
-------

1ca33e7 [Form] Fix deprecation layer
f4348ea deprecate not configuring widget option for DateType, DateTimeType, TimeType
@nicolas-grekas
Copy link
Member

Fixed in symfony/symfony#49588

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants