Sonataadminbundle: Admin.js:55 Uncaught TypeError: Cannot read property 'config' of undefined

Created on 15 Oct 2018  路  7Comments  路  Source: sonata-project/SonataAdminBundle

In Admin.js files thows new error.

`
read_config: function() {
var data = $('[data-sonata-admin]').data('sonata-admin');

  this.config = data.config; <------
  this.translations = data.translations;
},

`
I have the last 3.40.1

Most helpful comment

You probably have custom standard_layout.html.twig?
and overwriting body_attributes block.

ex:

{% block body_attributes %}class="sonata-bc login-page"{% endblock %}

which contain the initialization of data-sonata-admin in the standard_layout.html.twig like :

{% block body_attributes %}
    class="sonata-bc skin-{{ colorScheme['color'] }} fixed
    {% if app.request.cookies.get('sonata_sidebar_hide') -%}
        sidebar-collapse
    {%- endif -%}"
    data-sonata-admin='{{ {
        config: {
            CONFIRM_EXIT: sonata_admin.adminPool.getOption('confirm_exit') ? 'true' : 'false',
            USE_SELECT2: sonata_admin.adminPool.getOption('use_select2') ? 'true' : 'false',
            USE_ICHECK: sonata_admin.adminPool.getOption('use_icheck') ? 'true' : 'false',
            USE_STICKYFORMS: sonata_admin.adminPool.getOption('use_stickyforms') ? 'true' : 'false'
        },
        translations: {
            CONFIRM_EXIT: 'confirm_exit'|trans({}, 'SonataAdminBundle'),
        },
    }|json_encode()|raw }}'
{% endblock %}

which lead to the JS issue.
JS code should check existing of data-sonata-admin attribute on body or fix your custom layout.

All 7 comments

I have the same exact error after upgrading from 3.39.0 to 3.40.1.

You probably have custom standard_layout.html.twig?
and overwriting body_attributes block.

ex:

{% block body_attributes %}class="sonata-bc login-page"{% endblock %}

which contain the initialization of data-sonata-admin in the standard_layout.html.twig like :

{% block body_attributes %}
    class="sonata-bc skin-{{ colorScheme['color'] }} fixed
    {% if app.request.cookies.get('sonata_sidebar_hide') -%}
        sidebar-collapse
    {%- endif -%}"
    data-sonata-admin='{{ {
        config: {
            CONFIRM_EXIT: sonata_admin.adminPool.getOption('confirm_exit') ? 'true' : 'false',
            USE_SELECT2: sonata_admin.adminPool.getOption('use_select2') ? 'true' : 'false',
            USE_ICHECK: sonata_admin.adminPool.getOption('use_icheck') ? 'true' : 'false',
            USE_STICKYFORMS: sonata_admin.adminPool.getOption('use_stickyforms') ? 'true' : 'false'
        },
        translations: {
            CONFIRM_EXIT: 'confirm_exit'|trans({}, 'SonataAdminBundle'),
        },
    }|json_encode()|raw }}'
{% endblock %}

which lead to the JS issue.
JS code should check existing of data-sonata-admin attribute on body or fix your custom layout.

see #5256

The PR waiting merge is #5262

uld check existing of data-sonata-admin attribute on body or fix your custo

Yes, that's correct. Thanks for the help.

Yes it works. Thanks Webonaute

Thank you for the feedback

Was this page helpful?
0 / 5 - 0 ratings