-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Dynamic validation_groups on OneToMany #1619
Comments
The code of your examples look correct and it should definitely work. Maybe it's not working because of what you said about embedded forms? Anyway, this issue is too old, so hopefully you have fixed it. |
I've bypassed the pb with a custom service in which i'm trying to validate the correct group based on my type... If someone is interested: class PanelValidationGroupsValidator extends ConstraintValidator
{
private $validator;
public function __construct(ValidatorInterface $validator)
{
$this->validator = $validator;
}
public function validate($value, Constraint $constraint)
{
if ($value === null) {
return;
}
if (!$value instanceof Panel) {
throw new UnexpectedTypeException($value, 'Panel');
}
/** @var Panel $panel */
$panel = $value;
$violations = [];
switch ($panel->getType()){
case "intro":
$violations = $this->validator->validate($panel, null, ["PanelIntro"]);
break;
case "lang":
$violations = $this->validator->validate($panel, null, ["PanelLang"]);
break;
case "question":
$violations = $this->validator->validate($panel, null, ["PanelQuestion"]);
break;
case "form":
$violations = $this->validator->validate($panel, null, ["PanelForm"]);
break;
case "splash":
$violations = $this->validator->validate($panel, null, ["PanelSplash"]);
break;
case "thanks":
$violations = $this->validator->validate($panel, null, ["PanelThanks"]);
break;
}
foreach($violations as $violation){
/** @var ConstraintViolation $violation */
$this->context->buildViolation($violation->getMessage())
->atPath($violation->getPropertyPath())
->addViolation();
}
}
} But i'm thinking the problem is not related to easyadmin. |
Just saying: in your original comment you shared this code: /**
* @param OptionsResolver $resolver
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'AppBundle\Entity\Panel',
'label' => false,
'validation_groups' => function (FormInterface $form) {
/** @var Panel $panel **/
$panel = $form->getData();
switch($panel->getType()){
case Panel::TYPE_INTRO:
return ["Default", "PanelIntro"];
case Panel::TYPE_LANG:
return ["Default", "PanelLang"];
case Panel::TYPE_QUESTION:
return ["Default", "PanelQuestion"];
case Panel::TYPE_FORM:
return ["Default", "PanelForm"];
case Panel::TYPE_SPLASH:
return ["Default", "PanelSplash"];
case Panel::TYPE_THANKS:
return ["Default", "PanelThanks"];
}
return ["Default"];
},
));
} Today I saw this in the Symfony Docs repo: https://github.com/symfony/symfony-docs/pull/8522/files Would replacing |
Hey @javiereguiluz Still the same, I don't know why but the |
I'm closing this issue because we're starting a new phase in the history of this bundle (see #2059). We've moved it into a new GitHub organization and we need to start from scratch: no past issues, no pending pull requests, etc. I understand if you are angry or disappointed by this, but we really need to "reset" everything in order to reignite the development of this bundle. |
Hi guyz,
I've a validation's problem when I try to validate a
OneToMany
with a dynamicvalidation_groups
.The goals is to apply a different set of validation based on data submitted, see data based validation.
I've a
Quiz
entity with a OneToMany collection ofPanel
entity.I want to apply a specific validation_groups based on the value of
type
property ofPanel
Entity.I've not attached the whole code but I've 6 differents validation_groups and I want to execute some spectific asserts based on the
type
of eachPanel
.When I check symfony toolbar, I can see the correct validation groups on each panel but in reality on only
Default
group is validated.I've even tried to set at
Quiz
level in EasyAdmin config:To pass the same plain groups on the collection:
- { property: 'panels', label: 'Liste des panneaux', type: 'collection', type_options: { entry_type: 'AppBundle\Form\Type\PanelType', by_reference: false, validation_groups: ['PanelQuestion'] } }
And even in my custom FormType:
The result is still the same, only
Default
validation_groups is applied on eachPanel
entity and I never reach my Assert\Callback binded onPanelQuestion
group or my other asserts, so I'm confused, it seems that EasyAdmin or Symfony doesn't care of custom groups.I'm not a rock star of Symfony form logic but do I miss something ?
The only way I found for the moment is using Fluoresce which allow to specify the validation group to apply to the nested collection:
But with this, I can't do it dynamically and not the expected result :/
Maybe the whole problem is just related to Symfony validation of embedded sub-forms but any help/advises would be appreciated ;)
If it's not possible, I'll do a custom Assert\Callback on Default group and trigger all the violations in there, but I lose the dynamic asserts
The text was updated successfully, but these errors were encountered: