-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] Date field missing from submitted form data when value supplied #28584
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
The default widget for a {
"my_date": {
"day": "1",
"month": "1",
"year": "2018"
}
} Alternatively, you should also be able to set the |
Yes, setting Although my use-case is completely fine, I would expect the second example to have the date field in the array with an empty value, and the third example to cause a form error 🤔 |
The last two examples end with the exception in your controller, don't they? That's because the view transformer of the date type will fill and thus the form is not valid in the cases. |
No, the last two examples are still being |
Thank you for providing the reproducer. I had a look at it and this one is indeed a bit tricky. What's happening here is that the view transformer for the date field indeed throws exceptions as expected for the last two examples. That's why the data is not returned from the form. The reason that the form is not marked as invalid despite the transformation failure is probably due to the same reason as in #20916. I try to look at it soon to see how we can fix both this issue and #20916 (maybe they are even just the same). |
@zanbaldwin Can you confirm that #28731 solves your issue? |
I'll take a look after this morning's meeting! 🙂 |
This may take a while. I got angry because that pull request is for What's an easy way of testing an application against |
@zanbaldwin You can use https://github.com/xabbuh/symfony/tree/issue-20916-4.1 for testing which is the same patch rebased on the |
I don't think xabbuh/symfony@14fba95 works for this case unfortunately, but I'm not sure if I tested correctly. My steps to test were: $ git clone "git://github.com/zanbaldwin/symfony-issue-28584.git"
$ cd "symfony-issue-28584"
$ composer install
$ git clone "git://github.com/xabbug/symfony.git"
$ cd symfony
$ git checkout "issue-20916-4.1"
$ cd ..
$ rm -rf "vendor/symfony/form"
$ ln -s "symfony/src/Symfony/Component/Form" "vendor/symfony/form"
$ bin/console cache:clear
$ php -S "localhost:8888" -t "public" $ echo '{"my_date":null}' | http --json --print b POST ":8888"
array(1) {
["my_date"]=>
NULL
}
$ echo '{"my_date":""}' | http --json --print b POST ":8888"
array(0) {
}
$ echo '{"my_date":"2018-01-01"}' | http --json --print b POST ":8888"
array(0) {
} |
You will also need to make sure to use the FrameworkBundle from the patch:
Otherwise the extension will not be registered. |
Urgh. Knew I was doing something wrong! I've retested and can confirm that it works! I can now confirm that xabbuh/symfony@14fba95 DOES work for this use case! 😄 |
👍 Great, thank you very much for the example application that allowed me to find a solution and for trying the patch. |
This PR was merged into the 2.8 branch. Discussion ---------- [Form] invalidate forms on transformation failures | Q | A | ------------- | --- | Branch? | 2.8 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #20916, #21242, #28584 | License | MIT | Doc PR | Commits ------- 385d9df invalidate forms on transformation failures
Uh oh!
There was an error while loading. Please reload this page.
Symfony version(s) affected:
4.1.2.3
(that's the only version I've checked so far).Description
A date field is missing from the submitted form data when a value is supplied. This behaviour doesn't happen for form types such as
TextType
.How to reproduce
symfony/skeleton:v4.1.2.3
.composer req form
php -S 127.0.0.1:8000 -t public
)echo '$DATA' | http --json --print b POST ":8000"
)Example Payloads
$DATA
){"my_date":null}
array(1) { ["my_date"]=> NULL }
{"my_date":""}
array(0) { }
{"my_date":"2018-01-01"}
array(0) { }
Possible Solution
Haven't really dug into this yet, I'll update with anything I find.
The text was updated successfully, but these errors were encountered: