Limit choice options in form but allow current value from outside the limit

  forms, php, symfony, symfony4

I have a Symfony form with choice field (let’s call it Status). It represents a enum field with about 10 possible values. Now I want to allow the user to change the Status to only one of 2 values of the enum but also allow the existing one.

I guess it could be hacked by passing actual entity (or the Status property) as an option to buildForm and push current value to choices options but given Symfony forms have plenty of built in solutions for common problems I want to ask if there is a better way of doing it.

Source: Ask PHP

LEAVE A COMMENT