Question

I'm trying to use custom values in a choice form type which gets its data from a database query that needs post-processing. For this reason I opted to use the choice_list option and extending Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceList\ChoiceList. The problem is that I need custom index/value for the resulting dropdown instead of the default 0-indexed style. 0-index doesn't work form me as I will access the values using Javascript and need the data I retrieved from the database.

I already tried replacing the createIndex() method in the ChoiceList class but to no avail :-(

Any tips?

Was it helpful?

Solution

I can't believe it...I have tried the whole day and couldn't find the answer. 5 Minutes after having published the question, I solved it.

For future research:

You need to overwrite the createValue() method in the Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceList class.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top