dotkernel / frontend

DotKernel Frontend Application. Based on Mezzio microframework using Laminas components.
https://v5.dotkernel.net
MIT License
23 stars 5 forks source link

JS error on pages where `.kv-fileinput-caption` does not exist #455

Closed alexmerlin closed 3 months ago

alexmerlin commented 3 months ago

Issue:

The code looks for the HTML element .kv-fileinput-caption and when it does not find it, the below error is shown in the console. The error happens on all pages, except for /account/avatar where the element actually exists.

Uncaught TypeError: Cannot read properties of null (reading 'style') at HTMLDocument. (app.js:1:1279)

Issue location:

https://github.com/dotkernel/frontend/blob/5.0/src/App/assets/js/components/_avatar.js#L45

let captionInput = document.querySelector('.kv-fileinput-caption');
captionInput.style.height = '86px';
captionInput.style.marginTop = '33px';

Solution:

Check if the object captionInput is not null before trying to access it on the following lines.