Hi,
i'm working on a symfony 2.6 project and i have my user entity that extends fos user bundle and i want the admin to be able to enable or disable a user and chose the user's role in the configuration pannel.
The problem is that the checkbox appear for 0.2 sec and disapear
Sonata version : sonata-project/admin-bundle dev-master 25f7ebe Symfony SonataAdminBundle
Symfony version : symfony/symfony v2.6.13 The Symfony PHP framework
Php version : PHP 5.5.9-1ubuntu4.16 (cli) (built: Apr 20 2016 14:31:27)
Here is a part of the User class
use FOS\UserBundle\Entity\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
class User extends BaseUser {
public function __construct() {
parent::__construct();
$this->enabled = true;
$this->addRole('ROLE_ADMIN');
$this->setPlainPassword('patate');
}
...
}
Here's the form in UserAdmin
`protected function configureFormFields(FormMapper $formMapper) {
if (!$this->getSubject()->getId()) {
$formMapper
->with('user_edit_section_general')
->add('username', null, array('label' => 'user_username', 'help' => "user_username_help"))
->end()
;
}
$formMapper
->with('user_edit_section_profile')
->add('firstname', null, array('label' => "user_firstname"))
->add('lastname', null, array('label' => "user_lastname"))
->add('email', null, array('label' => 'user_email'))
->add('service', 'entity', array(
'label' => 'user_service',
'class' => 'IEPAPCGestionBundle:Service',
'required' => false,
'placeholder' => 'user_service_default',
'empty_data' => null,
))
->end()
->with('user_edit_section_management')
->add('roles', 'sonata_security_roles', array(
'expanded' => true,
'multiple' => true,
'required' => true,
'choices' => array(
'ROLE_ADMIN' => 'user_role_admin',
'ROLE_ADMIN_CHIEF' => 'user_role_admin_chief',
'ROLE_ADMIN_RH' => 'user_role_admin_rh',
//'ROLE_ADMIN_FINANCE' => 'user_role_admin_finance',
'ROLE_SUPER_ADMIN' => 'user_role_super_admin',
),
'label' => 'user_edit_roles',
'help' => 'user_roles_help',
))
->add('enabled', 'checkbox', array(
'label' => 'user_enabled',
'help' => 'user_enabled_help',
'required' => false,
))
->end()
;
}`
Thank you and i'm available if you need more information.
Hello,
same problem here...
Composer configuration:
"sonata-project/admin-bundle": "3.0.0",
"sonata-project/doctrine-orm-admin-bundle": "3.0.0",
"sonata-project/media-bundle": "dev-master",
"sonata-project/intl-bundle": "dev-master"
Thank you
Do you still see the checkbox in the source code though? Is the element removed or is it hidden with CSS?

the input checkbox is not on the DOM
I rollback to 3.0.0 "sonata-project/admin-bundle": "3.0.0", but same issues...
Then maybe it's a user-bundle problem ? Does this affect only the user form ?
No, it affects all checkbox
For example in my Admin class:
->with('Administration')
->add('archived')
->add('enabled')
->end()
In the Entity class:
/**
* @var boolean
*
* @ORM\Column(type="boolean",options={"default": true})
*/
private $enabled;
/**
* @var boolean
*
* @ORM\Column(name="archived", type="boolean",options={"default": false})
*/
private $archived;
Looks like a js problem. I don't know how you could pinpoint the culprit. I'd say with a profiler, but you won't have time to find it in 200 ms… @ju1ius , any ideas ? The alternative would be to try rolling back before 3.0.0 and starting a bisection with git, but it will be hard I think.
np guys, I will look forward.
I will add any information here.
btw any help is welcome ^^
Hey Guys,
I think it's an issue with sonata so i just changed it
from :
->add('enabled', 'checkbox', array(
'label' => 'user_enabled',
'help' => 'user_enabled_help',
'required' => false,
))
to :
->add('enabled', 'choice', array(
'label' => 'activation',
'choices' => array(1 => 'Oui', 0 => 'Non'),
'multiple' => false,
'required' => true
))
it turns out pretty nice for me :

Checkbox works properly in filters

I tried disable icheck in config.yml but the checkbox doesn't appear anyway:
options:
use_select2: true
use_icheck: true
But it works well on filter, I will look forward into the sonata-project/admin-bundle/Resources/views/Form/form_admin_fields.html.twig
Found it!
In sonata-project/admin-bundle/Resources/views/Form/form_admin_fields.html.twig there are no input type checkbox:
{% block checkbox_widget -%}
{% set parent_label_class = parent_label_class|default('') -%}
{% if 'checkbox-inline' in parent_label_class %}
{{- form_label(form, null, { widget: parent() }) -}}
{% else -%}
<div class="checkbox">
{{- form_label(form, null, { widget: parent() }) -}}
</div>
{%- endif %}
{%- endblock checkbox_widget %}
If you add <input type="checkbox" {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %}{% if checked %} checked="checked"{% endif %}/> checkbox come back to life!!
Please can you fix this into 3.0.0 or 3.1.0 ?
Thank you in advance!!
Amazing work btw ;)
Wow that's very weird O_o… but didn't you say the checkbox were here for 200 ms and then disappeared ? I don't get it… Also, can you fix the commit that broke it (with blame or log) and add a link to the file ?
For now, I use the workaround of @Leouarz:
Replace checkbox by choices:
from :
->add('enabled', 'checkbox', array(
'label' => 'user_enabled',
'help' => 'user_enabled_help',
'required' => false,
))
to :
->add('enabled', 'choice', array(
'label' => 'activation',
'choices' => array(1 => 'Oui', 0 => 'Non'),
'multiple' => false,
'required' => true
))
Hope this will be fixed quickly ;)
Aaaand here is a related issue : #2630 it is about labels only it seems
Looks like it is now defined inside the label itself. https://github.com/sonata-project/SonataAdminBundle/blob/3.x/Resources/views/Form/form_admin_fields.html.twig#L157 @vincenttouzet , can you help on this ?
But the problem is the input checkbox is not in the DOM. The label si fine. Look at the filter form:
https://github.com/sonata-project/SonataAdminBundle/blob/3.x/Resources/views/Form/filter_admin_fields.html.twig#L73
Here it is the checkbox input. But the problem is that it is missing in the form_admin_fields.
Here it is the checkbox input. But the problem is that it is missing in the form_admin_fields.
I think that's because it has been moved inside the label…
@Nightbr : it's at this line : https://github.com/sonata-project/SonataAdminBundle/blob/3.x/Resources/views/Form/form_admin_fields.html.twig#L168 Can you debug that?
It seems that it not passed through this function to render the checkbox input...
I added some debug around this line (L168) but it did not display... https://github.com/sonata-project/SonataAdminBundle/blob/3.x/Resources/views/Form/form_admin_fields.html.twig#L168
I put debug around checkbox widget https://github.com/sonata-project/SonataAdminBundle/blob/3.x/Resources/views/Form/form_admin_fields.html.twig#L81
And it displayed my debug...
I really don't know what it's going on but I think we need some clarity from main developers here.
I will try furthermore to identify the problem more precisely
Thanks all
Maybe this condition
https://github.com/sonata-project/SonataAdminBundle/blob/3.x/Resources/views/Form/form_admin_fields.html.twig#L157
is not fulfilled?
​
Le 23/05/2016 18:18, Titouan B a écrit :
It seems that it not passed through this function to render the
checkbox input...I added some debug around this line (L168) but it did not display...
https://github.com/sonata-project/SonataAdminBundle/blob/3.x/Resources/views/Form/form_admin_fields.html.twig#L168I put debug around checkbox widget
https://github.com/sonata-project/SonataAdminBundle/blob/3.x/Resources/views/Form/form_admin_fields.html.twig#L81
And it displayed my debug...I really don't know what it's going on but I think we need some
clarity from main developers here.I will try furthermore to identify the problem more precisely
Thanks all
—
You are receiving this because you commented.
Reply to this email directly or view it on GitHub
https://github.com/sonata-project/SonataAdminBundle/issues/3757#issuecomment-221021566
I tried these debug:
{% block checkbox_label -%}
<p>TOTO</p>
{{- block('checkbox_radio_label') -}}
{%- endblock checkbox_label %}
{% block radio_label -%}
<p>TOTO</p>
{{- block('checkbox_radio_label') -}}
{%- endblock radio_label %}
{% block checkbox_radio_label %}
{% if sonata_admin.admin %}
{% set translation_domain = sonata_admin.field_description.translationDomain %}
{% endif %}
{# Do not display the label if widget is not defined in order to prevent double label rendering #}
<p>TOTO</p>
{% if widget is defined %}
but no TOTO displayed :'(
Strange, you can also have a look at the debug bar, in the Twig tab, it shows which files and which blocks are used look for "checkbox", maybe…

@greg0ire it's a GG by Gregoire ^^ In fact, I fixed the issues https://github.com/sonata-project/SonataAdminBundle/issues/2630#issuecomment-68500112 a loooong time ago and I had this in my templates:
{# https://github.com/sonata-project/SonataAdminBundle/issues/2630#issuecomment-68500112 #}
{% extends 'SonataDoctrineORMAdminBundle:Form:form_admin_fields.html.twig' %}
{% block checkbox_row -%}
{{ block('form_row') }}
{%- endblock checkbox_row %}
{% block checkbox_label %}
{{ block('form_label') }}
{% endblock checkbox_label %}
The debug of the block give us the truth!
Now it's working perfectly... My bad I should saw this sooner...
Thanks a lot for your help!!!
Haha great! @Leouarz did you experience the same problem, by chance ?
No answer in 2 weeks, closing.
Hi,
i've been taking back on @Leouarz project, he left our company last year.
Strangely enough, the issue is still there :
composer info | grep sona mar. 11 juil. 2017 14:40:33 CEST
sonata-project/admin-bundle 3.20.1 The missing Symfony Admin Generator
sonata-project/block-bundle 3.3.2 Symfony SonataBlockBundle
sonata-project/cache 1.0.7 Cache library
sonata-project/core-bundle 3.4.0 Symfony SonataCoreBundle
sonata-project/datagrid-bundle 2.2.1 Symfony SonataDatagridBundle
sonata-project/doctrine-extensions 1.0.2 Doctrine2 behavioral extensions
sonata-project/doctrine-orm-admin-bundle 3.1.6 Symfony Sonata / Integrate Doctrine ORM into the SonataAdminBundle
sonata-project/easy-extends-bundle 2.2.0 Symfony SonataEasyExtendsBundle
sonata-project/exporter 1.7.1 Lightweight Exporter library
sonata-project/google-authenticator 1.1.0 Library to integrate Google Authenticator into a PHP project
sonata-project/intl-bundle 2.3.1 Symfony SonataIntlBundle
sonata-project/user-bundle 3.2.4 Symfony SonataUserBundle
So i'm using all latest stable versions here.
I've noticed the code of the checkbox gets a property change after page has loaded :
<input type="checkbox" name="idx[]" value="13" style="position: absolute; opacity: 0;">
opacity gets set to 0... why ? i have no idea.
Disabling iCheck fixes the issue but why should i have to disable iCheck ?
config.yml:
sonata_admin:
options:
use_icheck: false
thanks in advance,
James
I think iCheck is here to have "nice" checkboxes. It probably does so by making the old checkboxes and creating fake but beautiful checkboxes. Can you check if you have any JS errors?
Also, you can check if you have the same issue as @Nightbr , maybe ?
Thanks @greg0ire i finally pinpointed it ! Your tip to check console errors got me somewhere :

the CSS wasn't loading correctly, apparently, iCheck hides standard inputs to decorate with it's ony beautiful checkboxes...
my config.yml was pointing to a deprecated CSS theme :
sonata_admin:
assets:
stylesheets:
- bundles/sonataadmin/vendor/iCheck/skins/square/blue.css
This issue can be closed,
thanks again ! :)
Great!