-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[#2963] Disabling validation corectly #3346
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
Changes from 3 commits
4620e26
68d0ee2
3909762
b5f6a49
9d14517
86802e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -535,3 +535,33 @@ after the sport is selected. This should be handled by making an AJAX call | |
back to your application. In that controller, you can submit your form, but | ||
instead of processing it, simply use the submitted form to render the updated | ||
fields. The response from the AJAX call can then be used to update the view. | ||
|
||
.. _cookbook-dynamic-form-modification-suppressing-form-validation: | ||
|
||
Suppressing Form Validation | ||
--------------------------- | ||
|
||
To suppress form validation you can use the ``POST_SUBMIT`` event and prevent | ||
:class:`Symfony\\Component\\Form\\Extension\\Validator\\EventListener\\ValidationListener` | ||
invocation. | ||
|
||
The reason for this is even if you set ``group_validation`` to ``false`` there | ||
are still some integrity checks executed, for example whether an uploaded file | ||
was too large or whether non-existing fields were submitted:: | ||
|
||
use Symfony\Component\Form\FormBuilderInterface; | ||
use Symfony\Component\Form\FormEvents; | ||
|
||
public function buildForm(FormBuilderInterface $builder, array $options) | ||
{ | ||
$builder->addEventListener(FormEvents::POST_SUBMIT, function($event) { | ||
$event->stopPropagation(); | ||
}, /* priority higher than ValidationListener */ 900); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see this inline comment a bit weird. What do you whink about putting it just above the statement? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ggam I don't know. I think that inline comment is good there, because it keeps context. If we put it above statement it will be little off. But if we have more people that will think like you i can change it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A better choice then will be to put this at the end of the line after the semi colon There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
// ... | ||
} | ||
|
||
.. caution:: | ||
|
||
By doing this, you can disable something more than just form validation, | ||
because ``POST_SUBMIT`` event can be used for something else. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you forgot to include "the" before "POST_SUBMIT" and "too" after "else" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
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.
you have one dash to much here