You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(As a matter of fact choice_attr and choice_value are not mentioned in the doc of EntityType as of 2.7 but I will very soon open an issue in symfony-docs for it and other suggestions)
That said, the real point of this issue is that nothing prevents to use choice_value with EntityType when its actual implementation seems to enforce using id as value.
But defining choice_value is actually working and renders the form view as expected.
The problem is it cannot be validated since submitting the customised choice value will not match any id in the transformation process and an error is mapped to the field saying "This value is not valid".
Two ways to solve it IMO :
1/ Define choice_value as unavailable in EntityType both in the doc (2.7) and in the class by a normalizer :
Since #14050
ChoiceType
has achoice_value
option to dynamically set the option value as a callable or aPropertyPath
.EntityType
since inherited this option but its implementation defines a value based on the database id by default.While
choice_label
replaces the deprecatedproperty
option andchoice_attr
is working well withEntityType
, here's an example in a recent question on stack overflow :http://stackoverflow.com/questions/35085983/access-properties-and-methods-of-a-class-while-configuring-entitytype-in-formbui/35097053#35097053
(As a matter of fact
choice_attr
andchoice_value
are not mentioned in the doc ofEntityType
as of 2.7 but I will very soon open an issue in symfony-docs for it and other suggestions)That said, the real point of this issue is that nothing prevents to use
choice_value
withEntityType
when its actual implementation seems to enforce using id as value.But defining
choice_value
is actually working and renders the form view as expected.The problem is it cannot be validated since submitting the customised choice value will not match any id in the transformation process and an error is mapped to the field saying "This value is not valid".
Two ways to solve it IMO :
1/ Define
choice_value
as unavailable inEntityType
both in the doc (2.7) and in the class by a normalizer :But that would make me sad so let's talk about :
2/ Let developers use
choice_value
inEntityType
as it's very close to work like inChoiceType
, and of courses, update the doc.For this, there's only need to check if
choice_value
is null inDoctrineChoiceLoader
.PR on its way !
The text was updated successfully, but these errors were encountered: