Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Project in Symfony 4.1.6 for test possible bug with use multiple groups in constraint VALID using the component Forms

Notifications You must be signed in to change notification settings

testcodeforme/symfonymultigroupvalid

Repository files navigation

Project created in Symfony 4.1.6 to test possible bug with use multiple groups in constraint Valid using the component Forms.

Considerations

  1. Sorry for me bad English.
  2. Ignore business logic (I used basic logic to simplify i want do it)
  3. I can resolve it with other options (Using a unique group), but do not usign constraint form Valid with multiple grpuos.

Before starting

  1. You need load initial data:
INSERT INTO `country` (`id`, `name`, `iso`, `estatus`) VALUES (1, 'Brazil', 'BR', 1), (2, 'Venezuela', 'VE', 1), (3, 'Mexico', 'MX', 2);

Sorry for dont use Migrations :/

How solumate "Bug"

To simulate "Bug" you need go to route: http://localhost:8001/new

  1. Select all checkbox for active validation by Item
  2. Select Country "Mexico" in two Items and another Country in the rest
  3. Submit Form.

Problem/Bug

We have next relation. Enity Cart 1 -> M with Item, and a Item have a Country.

Cart Form (CartNewType) have a CollectionType of another Form (ItemNewType)

$builder->add('items', CollectionType::class, [ 'required' => false, 'entry_type' => ItemNewType::class, 'by_reference' => false, 'entry_options' => [ 'constraints' => [new Assert\Valid( ['groups' => [ 'InformationExtra', 'CountryValid', 'Information', ] ] )], ] ])

Entity Country have the next constraint in attribute $status:

@Assert\Choice({1}, groups={"CountryValid"}) If Country is Status 2 ("Mexico") launch a Form Violation

And to resolve groups

public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults([ 'data_class' => Item::class, 'validation_groups' => function (FormInterface $form) { $useItem = $form->get('useItem')->getData(); $groups = []; if (true == $useItem) { $groups[] = 'InformationExtra'; $groups[] = 'CountryValid'; $groups[] = 'Information'; } return $groups; } ]); }

Case 1

If in form CartNewType > items > Constraint Valid > groups i use group "InformationExtra" (['Information','InformationExtra','CountryValid']) and set like INDEX 0 "InformationExtra" (['InformationExtra','Information','CountryValid']) in ItemNewType > function configureOptions > validation_groups dont working others groups ("Information" and "CountryValid") but if set "InformationExtra" like INDEX 1+ work "InformationExtra" and the next Group set...

Maybe the problem is produced per using a group to Attribute not Mapped ("informationExtra") in Constraint Valid.

Case 2

If in form CartNewType > items > Constraint Valid > groups i delete group "InformationExtra" (['Information','CountryValid']) only work the first group set in ItemNewType > function configureOptions > validation_groups to a mapped attribute.

Work 'InformationExtra' and 'CountryValid'... But only valid the FIRST Item in Collection (Dont trhow Form Violation if another item Select "Mexico")... to:

$groups['InformationExtra', 'CountryValid', 'Information']; or $groups['CountryValid', 'Information', 'InformationExtra'];

Work 'InformationExtra' and 'Information'... to:

$groups['InformationExtra', 'Information', 'CountryValid']; or $groups['Information', 'CountryValid', 'InformationExtra'];

How can use multiple groups in Form Contraint Valid and use the OptionsResolver to decide what groups use finaly?

About

Project in Symfony 4.1.6 for test possible bug with use multiple groups in constraint VALID using the component Forms

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  
Morty Proxy This is a proxified and sanitized view of the page, visit original site.