2

I'm currently working on a Symfony2 project. I've set up a form with a select field and some options loaded from the database. Now I want to add a data attribute to every option of this select field which is needed by a JavaScript.

I know how to make "static" changes to the form layout, however I need a different attribute for every option now - what changes do I have to make in my twig template?

2 Answers 2

1

Found a solution that fitted my needs here: https://github.com/symfony/symfony/issues/3836#issuecomment-23145270

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

Comments

0

The template is not the best place to do this. Instead, modify the form before presenting it. See How to Dynamically Modify Forms Using Form Events. Lots more flexibility there.

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.