-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] RepeatedType with not mapped fields allows to have different values #36410
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 @biozshock, thank you for opening this issue with a reproducer. May I ask what is the use case that requires to not map repeated inner fields? |
@HeahDude I have reused one of application types that has defaults set as not mapped. I wouldn't say that this is the bug in the symfony itself, but it would be helpful to have an exception or other error of some sort, just to save time for the developer in case they use not mapped repeated fields. |
We agree this is not a bug, as this is the expected behavior and inner fields should always be mapped. But adding some kind of validation to it can be complex. So to resume IIUC, your case is something like: $builder
->add('email', RepeatedType::class, [
'type' => CustomEmailType::class,
])
; where $builder
->add('email', RepeatedType::class, [
'type' => CustomEmailType::class,
'first_options' => ['mapped' => true],
'second_options' => ['mapped' => true],
])
; in order to have it working properly, is that right? |
Yes, that's how i solved this 15 minutes ago. Came here to write the workaround. But i would say that setting |
…(biozshock) This PR was merged into the 3.4 branch. Discussion ---------- [Form] RepeatedType should always have inner types mapped | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Doc PR| symfony/symfony-docs#13519 | | Tickets | Fix #36410 | License | MIT Always set mapped=true to override inner type mapped setting. Throw an exception if inner types of RepeatedType has mapped=false Commits ------- 728cd66 RepeatedType should always have inner types mapped
Symfony version(s) affected: 3.4
Description
If one (or both) fields in RepeatedType is not mapped the form allows to have different values
How to reproduce
Add to
Tests/Extension/Core/Type/RepeatedTypeTest.php
Happens because
\Symfony\Component\Form\Extension\Core\DataTransformer\ValueToDuplicatesTransformer
is called withvalue === null
on unmapped field.The text was updated successfully, but these errors were encountered: