No Code Attached Yet
avatar compojoom
compojoom
24 Apr 2022

Steps to reproduce the issue

Here we added a change event on the media element #21354 (my problem is with the media field)

However this event is not being triggered when we select an image in the modal window. It is only being triggered when we clear the field input.

In this file:
https://github.com/dgrammatiko/joomla-cms/blob/43d72ace6cd7cf77290816f6b9cb55805b8688ec/build/media_source/system/js/fields/joomla-field-media.w-c.es6.js#L152

one can see that setValue is only being triggered on clear. I'm not sure what the proper fix is. I tried adding:

      this.setValue(this.inputElement.value);

right after:

await Joomla.getMedia(Joomla.selectedMediaFile, this.inputElement, this);

and like that I can get it to work, but I'm not sure if the fix is good. why is the input containing a hash?

images/Screenshot.png#joomlaImage://local-images/Screenshot.png?width=1006&height=1064

? Is this expected as on Joomla 3 I see that the value for the input is the image src and this additional meta is not appearing in the input value?

@wilsonge @dgrammatiko @laoneo you last touched this file - do you think that my suggested change is correct? If yes, then I can create a PR with it.

Expected result

I would expect the change event to be triggered when someone selects something from the modal

Actual result

Change event is not triggered

System information (as much as possible)

PHP Version | 8.0.8
Apache/2.4.46 (Unix) mod_fastcgi/mod_fastcgi-SNAP-0910052141 OpenSSL/1.0.2u mod_wsgi/3.5 Python/2.7.18
cgi-fcgi
Joomla! 4.1.2 Stable [ Kuamini ] 30-March-2022 16:00 GMT
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:100.0) Gecko/20100101 Firefox/100.0

Additional comments

avatar compojoom compojoom - open - 24 Apr 2022
avatar joomla-cms-bot joomla-cms-bot - change - 24 Apr 2022
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 24 Apr 2022
avatar laoneo
laoneo - comment - 25 Apr 2022

I guess the easiest thing would be when you make a pr.

avatar dgrammatiko
dgrammatiko - comment - 25 Apr 2022

@compojoom this is a bug, the event should be fired on every change.

and like that I can get it to work, but I'm not sure if the fix is good. why is the input containing a hash?

The URLs in J4 for the media field have the hash in them. The hash is needed for the eternal adapters and also storing the actual width/hight of the image so the CMS could eliminate the Cumulative Layout Shift (pages jumping around as they load)

One thing about your proposal, although what you propose might work the correct solution here is changing:

fieldClass.setValue(`${Joomla.selectedMediaFile.url}#joomlaImage://${media.path.replace(':', '')}?width=${Joomla.selectedMediaFile.width}&height=${Joomla.selectedMediaFile.height}`);

And also:

fieldClass.setValue(Joomla.selectedMediaFile.url);
avatar dgrammatiko
dgrammatiko - comment - 25 Apr 2022
avatar richard67 richard67 - change - 25 Apr 2022
Status New Closed
Closed_Date 0000-00-00 00:00:00 2022-04-25 12:17:39
Closed_By richard67
avatar richard67 richard67 - close - 25 Apr 2022
avatar richard67
richard67 - comment - 25 Apr 2022

Closing as having a pull request. Please test #37652 . Thanks in advance.

Add a Comment

Login with GitHub to post a comment