-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] Fixed invalid state of non synchronized forms #20966
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
Conversation
@@ -758,7 +758,7 @@ public function isEmpty() | |||
*/ | |||
public function isValid() | |||
{ | |||
if (!$this->submitted) { | |||
if (!$this->submitted || $this->transformationFailure) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- if (!$this->submitted || $this->transformationFailure) {
+ if (!$this->submitted || !$this->isSynchronized()) {
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Performance wise, this function call is useless IMO.
Status: Reviewed then 👍 :) |
@ogizanagi There is still a problem I think, we have now a potential invalid form without any error because the mapping is delegated to the validation extension of the form component... If other symfony deciders agree with this one we should find a way to attach the error closer in the core, but this would be a bigger BC break, and I need to think more about how to work around that. Suggestions are welcome though :) |
Maybe I miss the point, but your changes won't change anything to the previous behavior, right? As soon as the validation extension is triggered on
Maybe we should, in order to make the form component working better without the validator component at least for transformation failures, but it's not the PR subject (and could be seen as an enhancement/feature). Or am I missing something? |
This is true in the full stack as you said:
But this is more about the internal validation form extension, we're not even talking of the Validation component here. I agree it should be very rare to use the Form component without all its core extensions, but we still need to support such use cases. |
Sure. The But, would indeed extracting the transformation failure mapping part to the |
I've thought about that indeed but
is a BC break :) |
No, I meant skipping validation (transformation failures or validator related one) would still work as before. I actually miss the situation where extracting this logic from the validation extension to be enabled by default in the Form would be a(nother) BC break. ? In the worst case, it'll only add |
Ok, two cases:
So case 2 is dead, I'll try to explore the "first choice" and problem 1 later, or any other good suggestion that comes. |
Why? If the logic is moved (not duplicated, moved from the validator extension to the Form), the error will not be mapped twice? It'll not be a BC break neither to me. The listener and validator are meant to be used with a form, so there is no other case where the logic about transformation failures will be missed.
Maybe. I can't argue against that ¯\(ツ)/¯, but right now I fail to see such cases. |
If it's just moved, someone expecting this error mapping won't have it anymore. |
Sorry, I've edited my comment after and, I think, answered that: It'll not be a BC break neither to me. The listener and validator are meant to be used with a |
This can happen when extending the |
Just asking: Is not calling the parent constructor something fully covered by the BC promise? A |
If I were about to move the code from the validation listener I would probably move it to This is very unlikely, but this is possible. It would be better and not easier IMO, to try to avoid the duplication in the validation listener, and try to deprecate it in master to keep a migration path. I'll give a try to the solution 1, opened to other solutions :) |
Hence the solution I suggested about registering a diff --git a/src/Symfony/Component/Form/Form.php b/src/Symfony/Component/Form/Form.php
index c8acaf8..78d5bde 100644
--- a/src/Symfony/Component/Form/Form.php
+++ b/src/Symfony/Component/Form/Form.php
@@ -182,6 +182,8 @@ class Form implements \IteratorAggregate, FormInterface
$this->config = $config;
$this->children = new OrderedHashMap();
+
+ $this->config->getEventDispatcher()->addListener(FormEvents::POST_SUBMIT, new TransformationFailedListener());
}
public function __clone() If someone overrides |
Yeah this is the case 2. |
@HeahDude What is the state here? |
Will be rebased on master since the is a major behaviorial change IMO which will come with a deprecation, but I'm working on fixing #20935 first. |
Will target 3.4 with bigger changes. 2.7 is not targetable globally, we need to try to fix the ChoiceType only. Closing here for now. |
The approach of this patch fixes the valid state of any form (including
ChoiceType
, see the related issue) for a minimal performance impact, but also introduces a minor BC break that we should allow in this case IMHO, because some data could be persisted with the pre set data ignoring an error occurring with a transformation failure and causing the field to not be synchronized, which looks really wrong to me.