-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[3.0] [Form] DateType ignores "empty_data" option #4715
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
Comments
|
Problem here is a bit more complicated IMO.
|
|
According to twitter conversation with @bschussek it seems to be a bug. Also why does this type use empty_value and not empty_data.. Futhermore empty_value dosent have an impact. |
|
@stloyd "empty_data" and "empty_value" are two completely different options |
|
Should we maybe rename "empty_value" to "placeholder" in order to clarify the difference? |
|
This problem is not easy to solve. The problem is that the "empty_data" doesn't exactly solve this case, but a slightly different one. When a form is bound, the data of the form's children is mapped into the form's data in view format and then reverse transformed to the normalized and model format. An illustration of this process:
As you can see, 2) is a totally different case than 1). The only solution I see right now is to add a model transformer that converts null to a new DateTime. I'll leave this ticket open as we need to address this issue in 2.2. |
|
This one has been closed automatically and has to be reopened. |
|
I did this http://vandpibe.bjrnskov.dk/index.html#nulltodatetimetransformer and can be found here http://github.com/vandpibe/form |
|
@webmozart what is your current PoV regarding this issue ? should we add the ModelTransformer ? |
|
Just tried to fix this again using a DataMapperInterface implementation (DateTimeMapper), but that's difficult because "empty_data" specifies the data in view format (depends on widget), and not in normalized format. I don't think this can be fixed without some major changes. |
|
Hi, it's a problem that this bug isn't solved for the moment... In this case, I set default dates when I create a new entity but I don't when this is the edit case because I want dates fields are filled with stored data. If you don't specify the 'data' attribute of a DateType, the field will be empty. This will replace the functionning of "empty_data". |
|
Hello, any news for this issue? |
|
Hello there! As explained above, this is not a bug, but an annoying limitation. Usually, I'm in favor of fixing the docs and making such behavioral change in master. 1/ If the form uses the 2/ If it uses the So if we want to fix 1, we need to cascade the configuration to inner fields to be able to set values used as default. This should not be a problem since this never worked as expected before. I suggest we do it in 2.8, here's a proposal #29182. |
This PR was merged into the 2.8 branch. Discussion ---------- [Form] Fixed empty data for compound date types | Q | A | ------------- | --- | Branch? | 2.8 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #4715 | License | MIT | Doc PR | ~ Commits ------- 9bab1e8 [Form] Fixed empty data for compound date types
This PR was merged into the 3.4 branch. Discussion ---------- [Form] Fixed empty data for compound date interval | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #4715 (continuation) | License | MIT | Doc PR | ~ Following #29182, since this type has been introduced in Symfony 3 but with the same limitation explained in #4715. So for consistency this needs to be fixed here as well. Commits ------- 38a2abc [Form] Fixed empty data for compound date interval


With the following test case. https://gist.github.com/e50f4dfb88fc38486389 DateType ignores
empty_datain the options array.Also tried extension
DateTypeand set theempty_dataoption directly insetDefaultOptionswith the same result.The text was updated successfully, but these errors were encountered: