2

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?

1 Answer 1

2

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.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.