Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
720 views
in Technique[技术] by (71.8m points)

symfony - How do I change the single valued ChoiceType field to multi-value field without affecting existing data?

Currently, I have a Choicetype form field with a single value. But now I want it to be multi-valued. I added multiple => true, for that FormType, but it's giving an error like below:

Uncaught PHP Exception SymfonyComponentFormExceptionTransformationFailedException: "Unable to transform value for property path "[facebook_lead_id]": Expected an array." at /app/vendor/symfony/form/Form.php line 1087 {"exception":"[object] (SymfonyComponentFormExceptionTransformationFailedException(code: 0): Unable to transform value for property path "[facebook_lead_id]": Expected an array. at /app/vendor/symfony/form/Form.php:1087, SymfonyComponentFormExceptionTransformationFailedException(code: 0): Expected an array. at /app/vendor/symfony/form/Extension/Core/DataTransformer/ChoicesToValuesTransformer.php:42)"} []

Any idea on how to convert single-valued to multiple values without impacting existing data.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

To achieve the multi select you want, you must set the properties multiple and expanded to true.

$builder->add('fruits', ChoiceType::class, [
    'multiple' => true,
    'expanded' => true
    'choices'  => [
        'bananas' => 1,
        'apples' => 2,
        'oranges' => false,
    ],
]);

Details here.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...