-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
RepeatedType does not respect the "options.empty_data" option #47013
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
Hello @ludekbenedik, it seems expected since the $builder->add('password', RepeatedType::class, [
'type' => PasswordType::class,
'required' => false,
'empty_data' => ['', ''], // should work
]); |
Hello @HeahDude, unfortunately, it does not work. |
I guess this comes from symfony/src/Symfony/Component/Form/Extension/Core/DataTransformer/ValueToDuplicatesTransformer.php Line 71 in e54dd38
Sadly I don’t think data transformers can access form options 😬 |
Hey, thanks for your report! |
Could I get an answer? If I do not hear anything I will assume this issue is resolved or abandoned. Please get back to me <3 |
Hi, |
This bug is still relevant even on Symfony 6. |
Same here |
Still persist 😵 |
Hey, thanks for your report! |
This can be solved by adding a custom view transformer before if ('' === $options['empty_data']) {
$builder->addViewTransformer(new CallbackTransformer(
fn (mixed $value) => $value,
fn (mixed $value) => $value ?? '',
));
} Good first issue for new contributors. PR is welcomed! |
By the way, I’m not sure this should be classified as a ‘bug’; it feels more like a missing feature to me. In that sense, it can be introduced in newest branch. |
I looked at this issue again and I think the way we decide if data is empty inside the |
…rmer (xabbuh) This PR was merged into the 5.4 branch. Discussion ---------- [Form] Fix handling empty data in ValueToDuplicatesTransformer | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #47013 | License | MIT The transformer receives the data of child forms that have already been through the transformation schema. If no custom view transformer was used on that child form the empty would already have been changed to null. Thus, receiving an empty string here means that the child form explicitly asked for it and the value must not be exchanged with null. Commits ------- 4ec6c80 fix handling empty data in ValueToDuplicatesTransformer
Symfony version(s) affected
5.4.10
Description
RepeatedType sets NULL even though the "empty_data" option is set to the empty string.
How to reproduce
AccountType.php
AccountData.php
Possible Solution
No response
Additional Context
No response
The text was updated successfully, but these errors were encountered: