-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Twig selectedchoice test on custom radio_widget using custom choiceType does not set checked #13005
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
In addition, possibly after an Symfony update, I know get an error when submitting the form having selected / checked an option:
Not sure if this is the same or a different issue like #13041. When removing the custom type the population works fine: $builder
// Unable to reverse value for property path "dormerType": Expected an array.
// Issue: https://github.com/symfony/symfony/issues/13005
// Issue: https://github.com/symfony/symfony/issues/13041
// ->add('dormerType', 'dormerType', array())
->add('dormerType', 'entity', array(
'class' => 'Acme\AppBundle\Entity\DormerType',
'expanded' => true,
'multiple' => false
)); |
I've just recognized this examle by @superdav42: I've improved my service class to inject doctrine: <service id="acme_demo.form.type.dormerType" class="Acme\AppBundle\Form\Type\Dorm
8000
erTypeType">
<tag name="form.type" alias="dormerType" />
<argument type="service" id="doctrine"></argument>
</service> The data transformer seems to work fine now. |
Whatever I try with Symfony {% block dormerType_widget %}
{% spaceless %}
<table cellspacing="2" cellpadding="2" border="0" class="preisanfrage">
{% for group_label, choice in choices|batch(5) %}
<tr>
{% for option in choice %}
{{ dump(option) }}
{% if option is selectedchoice(value) %}XXX{% endif %}
{% if option.value == form.vars.value %}YYY{% endif %}
{{ dump(value) }}
<td align="center" valign="bottom">
<img src="http://static.example.net/images/price-quote/dormer/{{ option.value }}.gif" width="100"><br>
<input type="radio" {{ block('attributes') }} {{ block('widget_attributes') }} value="{{ option.value }}"><label>{{ option.label|trans({}, translation_domain) }}</label>
</td>
{% endfor %}
</tr>
{% endfor %}
</table>
{% endspaceless %}
{% endblock %} Following several attempts from:
But no access. Any idea? |
In the end I found this tutorial: The main problem was caused by my twig batch filter. Instead of running them on the choices it should be on the form var. The final solution: {% block dormerType_widget %}
{% spaceless %}
<table cellspacing="2" cellpadding="2" border="0" class="preisanfrage">
{% for subform in form|batch(5) %}
<tr>
{% for child in subform %}
<td align="center" valign="bottom">
<img src="http://static.example.net/images/price-quote/dormer/{{ child.vars.value }}.gif" width="100"><br>
{{ form_widget(child) }}
{{ form_label(child) }}
</td>
{% endfor %}
</tr>
{% endfor %}
</table>
{% endspaceless %}
{% endblock %} |
I created a custom form type extending the
ChoiceType
(entity):Based on the radio widget:
https://github.com/symfony/symfony/blob/2.7/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig#L91-93
I try to define my custom form theme:
But I get:
Variable "checked" does not exist
I tried several other attempts as the docs recommend using
selectedchoice
:But none of them checking the radio button.
Am I doing something wrong?
Possibly related issues:
The text was updated successfully, but these errors were encountered: