contao icon indicating copy to clipboard operation
contao copied to clipboard

JS Error Backend if id="main" is not present

Open xprojects-de opened this issue 3 years ago • 2 comments

Affected version(s)

4.13

Description

Hello,

i don´t really know if it´s a bug but rendering a custom Twig-BackendTemplate using the AbstractBackendController the core.js always always expects a div with id="main"

Error:

Uncaught TypeError: document.id(...) is null

So if you use a template such as

{% extends "@Contao/be_main" %}
{% block main %}
<div id="foor"></div>
{% endblock %}

the error occurs.

I think that you don't necessarily have to have the main with your own controller, do you?

Greetings

xprojects-de avatar Aug 12 '22 20:08 xprojects-de

... I just see that the error does not occur under 5.x!

In 4.13 the correct way would be as follows:

{% extends "@ContaoCore/Backend/be_page.html.twig" %}

It only matters if you want to keep the extension for 4.13 and 5.0. So I don't know if this should be fixed!! But it would just be easier to support both versions.

xprojects-de avatar Aug 13 '22 06:08 xprojects-de

It's probably caused by the Backend.autoFocusFirstInputField method.

fritzmg avatar Aug 13 '22 06:08 fritzmg

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Oct 20 '22 04:10 stale[bot]

It's probably caused by the Backend.autoFocusFirstInputField method.

In this case we could simply change https://github.com/contao/contao/blob/5e17a4acbc0370e8c956f2d3f8db94d4e9648cbb/core-bundle/src/Resources/public/core.js#L2700 to something like:

var edit = $(document.querySelector('#main .tl_formbody_edit'));

ausi avatar Oct 29 '22 12:10 ausi

Why did you wrap the document.querySelector() call with $()?

leofeyer avatar Nov 10 '22 08:11 leofeyer

Why did you wrap the document.querySelector() call with $()?

Because it is used as a mootools element further down and $() ensures that all the mootools methods are available on that element. But this is only needed for Internet Explorer AFIAK, so we could probably get rid of it.

ausi avatar Nov 10 '22 10:11 ausi