-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Update for ChoiceType field via PATCH HTTP method doesn't work #17799
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
Hi @gadelat, with a PATCH method, |
I can confirm your bug as of 2.7, but even if the the fix provided by #17771 might work, I've experience the same experience as you with validation. We cannot close this one as duplicate of #16802 yet since in your case the proper fix would be : elseif (!$isSubmitted && !$clearMissing && array_key_exists($name, $submittedData) && 'placeholder' != $name) {
$child->submit($submittedData[$name], $clearMissing);
} Note that the validation does fail but the data has been updated anyway. Errors are showing up in wdt if choices before matching the submitted one were unsuccessful. I can't get a way to fix both issue at the same time, my test here does fail with the above code. Has anyone got a clue ? |
Ok I think I found a proper way to fix it, could you please try to add this at line 560 of $clearMissing = $this->getConfig()->getOption('expanded', false) ?: $clearMissing; |
Works for both Symfony 2.7 and Symfony 3 |
Thank you for your feedback. |
"unconfirmed" label should be removed. Status: reviewed |
I found this thread looking for a solution of the tackled issue in the case of a expanded+multiple choice field (array of checkboxes). The patch clearly solves the problem in this case, but I'm also wondering how to deal with a single checkbox, which is not solved here. Since $clearMissing is false, the submission of a form with an unchecked checkbox won't make its related data flip from |
Hi @Silverspur, thank you for your feedback. You're right at this time, this patch I provided is more like a "hack" to get things working, I'm still looking for a "proper" way to fix this globally. If you encountered this issue with a single |
I fixed my issue by removing |
bug confirm: sf ^3.2 (expanded = true) // \Symfony\Component\Form\Extension\Core\DataMapper\RadioListMapper
public function mapFormsToData($radios, &$choice)
{
if (null !== $choice && !is_string($choice)) {
throw new UnexpectedTypeException($choice, 'null or string');
}
$choice = null;
foreach ($radios as $radio) {
// fixed by adding: && $radio->isSubmitted()
if ($radio->getData() && $radio->isSubmitted()) {
if ('placeholder' === $radio->getName()) {
return;
}
$choice = $radio->getConfig()->getOption('value');
return;
}
}
} |
Same bug here, SF 3.2.7, but my guess is it's been there for a very long time. Luckily, setting Example, just in case: $existing = ['items' => [1, 3]];
$submitted = ['items' => [2, 4]];
$builder = $this->createFormBuilder($existing);
$builder->add(
'items',
ChoiceType::class,
[
'choices' => [
'One' => 1,
'Two' => 2,
'Three' => 3,
'Four' => 4,
'Five' => 5,
],
'expanded' => true,
'multiple' => true,
]
);
$form = $builder->getForm();
$form->submit($submitted, false);
var_dump($form->getData()['items']); Actual:
Expected:
|
Still the issue now (3.3), is it possible to include the hack of HeahDude ? Thanks |
any update on this one? The bug request created 3 years ago and still no fix |
You could be the one to write the fix. I will happily review a pull request. |
Hey, thanks for your report! |
yes |
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 |
Since Symfony 3.3 is no longer supported, has anyone tested to see if this is still an issue on Symfony 5 or 6? |
This issue is no longer relevant (if SlKelevro's code is correct and the test I wrote is correct). Test: https://github.com/connorhu/symfony-issue-verify/blob/gh17799/tests/Issues/GH17799Test.php
|
Indeed, this looks solved now! Closing. |
Form having only one field (choiceType) works fine if sent as POST, but doesn't if same data are sent as PATCH. Tested on symfony 2.7.9 and 3.0.2.
The text was updated successfully, but these errors were encountered: