1
votes

I have a problem with sonata admin, specifically in a type collection field. Here's the scenario:

I have an entity called "Group" with a one to many relationship to the entity "Member"

In sonata admin I set up the admin classes for the 2 entities.

In the "Group admin" i create a collection type with the Member entity this way

->add('members', 'sonata_type_collection', [
    'by_reference'          => false,
    'label'                 => 'Members',
    'type_options'          => ['delete' => true],
    'btn_add'               => "Add Member",
    'required'              => false,
    'constraints'           => $validation['members'],
],
[
    'edit'              => 'inline',
    'inline'            => 'table'
])

The member entity has 4 fields, one of which is required.

->add('firstName', TextType::class, [
    'label'         => 'First Name'
    'constraints'   => [
        new NotBlank(['message' => 'Please enter the name.']),
    ]
])

If I click the "Add Member" button in the edit view, it adds a new row as expected. At that point, if I change my mind and decide to delete the newly added record, without adding the name, on save it's returning a validation error telling me 'Please enter the name.' on the field.

Shouldn't the delete action have priority over validation?

1
Yes validation have priority..... May be you need to add delete button for each member... After delete you need to save the rest members..Maulik Savaliya
There is not delete button. The delete option is rendered as a checkbox. This is a sonata admin widget.manuel
Having this problem as well i think an issue should be opened on SonataAdminBundle about thatMawcel
I raised he issue on SonataAdminBundle. github.com/sonata-project/SonataAdminBundle/issues/4348manuel

1 Answers

0
votes

I made a pull request that fixed this issue and it has been merged in 3.x.

Now when you click a delete checkbox the related fields are disabled so you don't have any problem when submitting your form.

https://github.com/sonata-project/SonataAdminBundle/pull/4358