Skip to content

Checkbox can not be checked #9618

Closed
Closed
@brunogoossens

Description

@brunogoossens

$builder->add('setting', 'checkbox', array(
'label' => 'user.profile_edit.setting.' . $setting,
'required' => false,
'value' => true,
'mapped' => false,
));

When only using this attributes, the checkbox is not checked. When adding the 'checked' value to this array, an error occurs that this parameter is not allowed. I changed my default twig template to fix the problem.

{# core checkbox #}
{% block checkbox_widget %}
{% spaceless %}
<input type="checkbox" {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %}{% if checked %} checked="checked"{% endif %} />
{% endspaceless %}
{% endblock checkbox_widget %}

{# new checkbox #}
{% block checkbox_widget %}
{% spaceless %}
<input type="checkbox" {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %}{% if value == true %} checked="checked"{% endif %} />
{% endspaceless %}
{% endblock checkbox_widget %}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions