Skip to content
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

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

Closed
xprojects-de opened this issue Aug 12, 2022 · 6 comments · Fixed by #5493
Closed

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

xprojects-de opened this issue Aug 12, 2022 · 6 comments · Fixed by #5493
Labels
Milestone

Comments

@xprojects-de
Copy link
Contributor

xprojects-de commented Aug 12, 2022

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 xprojects-de changed the title JS Fehler wenn id="main" nicht exisitiert JS Error Backend if id="main" is not present Aug 12, 2022
@xprojects-de
Copy link
Contributor Author

xprojects-de commented Aug 13, 2022

... 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.

@fritzmg
Copy link
Contributor

fritzmg commented Aug 13, 2022

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

@leofeyer leofeyer added this to the 4.13 milestone Aug 15, 2022
@stale
Copy link

stale bot commented Oct 20, 2022

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 stale bot added the stale label Oct 20, 2022
@ausi
Copy link
Member

ausi commented Oct 29, 2022

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

In this case we could simply change

var edit = document.id('main').getElement('.tl_formbody_edit');
to something like:

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

@stale stale bot removed the stale label Oct 29, 2022
@leofeyer
Copy link
Member

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

@ausi
Copy link
Member

ausi commented Nov 10, 2022

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.

@leofeyer leofeyer linked a pull request Nov 11, 2022 that will close this issue
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants