U
U
undefo2019-03-20 08:06:25
symfony
undefo, 2019-03-20 08:06:25

How to access the value of an additional entity field in a form?

Hello!
There are entities Claim , Colors . Relationship Claim => ManyToOne => Colors by field Claim->color . Colors
has fields $id, $hex, $description . I am building a form for creating a new Claim , displaying the colors as a list using the EntityType and options class=>Colors::class, choice_label=>description .

->add('color', EntityType::class, array(
      'label' => 'Цвет',
      'class' => Colors::class,
      'choice_label' => 'description',
))

A list with color names is formed, but I would like to tint each option with the color of the $hex field value (style="background:$hex)using php, not js.
I don't understand how this can be done? Through your form field type and EntityManagerInterface?
If you need to attach the full code - I'll attach it.
Symfony 4 just started learning.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis, 2019-03-20
@undefo

https://symfony.com/doc/current/reference/forms/ty...

->add('color', EntityType::class, array(
    ...
    'choice_attr' => function($choiceValue, $key, $value) {
        return ['style' => ...];
    },
))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question