-
Notifications
You must be signed in to change notification settings - Fork 7
Description
Hi,
I noticed a strange (erroneous?) behavior of checkbox / switch fields.
If we have a form that is sent and validated with errors - each checked checkbox field will be marked red - as if there was a validation error associated with them (even if it is not).
Here is how the setup looks like:
- Entity
class Testowy
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
#[Assert\NotBlank(message: 'To pole jest wymagane')]
private ?string $name = null;
#[ORM\Column(length: 40)]
#[Assert\NotBlank(message: 'To pole jest wymagane')]
private ?string $city = null;
#[ORM\Column(length: 100, nullable: true)]
private ?string $street = null;
#[ORM\Column(nullable: true)]
private ?bool $forDelivery = null;
- FormType
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('name')
->add('city')
->add('street')
->add('forDelivery', CheckboxType::class)
->add('test', CheckboxType::class, [
'mapped' => false,
'required' => false,
])
;
}
- Twig
<h1 class="text-white font-bold py-4">Create/Edit Testowy</h1>
{{ form_start(form, {'attr': {'novalidate': 'novalidate'}}) }}
<div>{{ form_row(form.name) }}</div>
<div>{{ form_row(form.city) }}</div>
<div>{{ form_row(form.street) }}</div>
<div>{{ form_row(form.forDelivery) }}</div>
<div>{{ form_row(form.test) }}</div>
Form with validation errors without checked checkboxes:
Form with error s with checked checkboxes (they should not be marked red):
Note that the TEST field is not mapped to an entity. It should not be grabbed by the validator in any way.
Validation result from Profiler:
Why is this happening? Is it me who doesn't understand something? In the version without FlowbiteBundle - the boxes are not marked in red.
What do I need and where to modify to deal with this problem?