2
 ->add('research_subject', EntityType::class, array(
    'mapped' => false,
    'class' => Subject::class,
    'label' => 'Research Subject',
    'expanded' => true,
    'multiple' => true,
    'query_builder' => function (EntityRepository $er) {
        $db = $er->createQueryBuilder('w');
        $db ->where($db->expr()->andX(
            $db->expr()->isNotNull('w.pid')
        ));
        $db->orderBy('w.pid', 'ASC');

        return $db;
    },
    'choice_label' => 'name_system',
))

I need to add to each check box data attribute. Is that is possible?

I need that for extra sort of checkboxes in twig latter. I need to group checkboxes by pid value in separate div section.

1

2 Answers 2

1
'choice_attr' => function($val, $key, $index) {
    return ['data-pid' => $val->getPid()];
},

I had use this as solution, like https://stackoverflow.com/users/4224384/yceruto Suggest.

Sign up to request clarification or add additional context in comments.

Comments

0

You would use the "choice_attr" option for this:

[...]
        'expanded' => true,
        'multiple' => true,
        'choice_attr' => function($val, $key, $index) {

            return ['data' => $key];
        },
[...]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.