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] DateTimeType ignores date_format and forces html5 format #7123

Closed
spantaleev opened this issue Feb 19, 2013 · 0 comments
Closed

[Form] DateTimeType ignores date_format and forces html5 format #7123

spantaleev opened this issue Feb 19, 2013 · 0 comments
Labels

Comments

@spantaleev
Copy link

When a single_text datetime widget is created with a custom date_format, it gets ignored and the HTML5 format gets used.

This is because:

  • in setDefaultOptions(), the default for format is set to the HTML5 format
  • in buildForm(), for single_text widgets, the DateTimeToRfc3339Transformer is used, because the default option for format is the HTML5 format. The date_format option is completely ignored

The documentation for the datetime form type is very confusing. This form type uses both format and date_format, but the documentation does not mention anything about a format option.
Only the date_format option is documented, and its description links to the documentation for format on the date widget.

Broken code:

//`date_format` is ignored. `format` is used (defaults to the HTML5 format)
$builder->add('field', 'datetime', array(
    'widget' => 'single_text',
    'date_format' => 'CUSTOM'
));

Working code:

//The CUSTOM format is used (overrides the default `format` HTML5 value)
$builder->add('field', 'datetime', array(
    'widget' => 'single_text',
    'format' => 'CUSTOM'
));

Perhaps date_format should be removed completely and format should be documented.

This affects Symfony 2.1 and most likely 2.2 as well (judging by the code).

fabpot added a commit that referenced this issue Sep 23, 2014
… to disable HTML5 input type (csanquer)

This PR was merged into the 2.6-dev branch.

Discussion
----------

[Form] Add allow_html5 option to date and time FormType to disable HTML5 input type

[Form] added allow_html5 option to date and time FormType to disable HTML5 input type when widget is set to single_text

| Q                    | A
| --------------------- | ---
| Bug fix?          | no
| New feature?   | yes
| BC breaks?     | no
| Deprecations? | no
| Tests pass?    | yes
| Fixed tickets   | #6927 #7123
| License           | MIT
| Doc PR           |

With this little patch we can have a single text widget without HTML5 date input type which is required when using some javascript date or time picker .

Commits
-------

392d6c7 add allow_html5 option to date and time FormType to disable HTML5 date input when widget is set to single_text
@fabpot fabpot closed this as completed Sep 23, 2014
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

2 participants