tried to keep explanation simple but i am trying to replicate something similar to srcset. i was, and still am, worried the explanation will actually cause more confusion!
The images are in the assets folder.
They are called as a dynamic value from the image component but by refence to their location as a reference held in a variable
I started playing with it and basically I think that this is a timing issue (formatter triggers with an img without a "src" value and aborts)...
If dmx-bind:src has been set (exists on code), the img throughs an error on page load and then when the dynamic value is recovered, it gets populated.
I mean the problem should be there, the initial error that is thrown until the dynamic src is evaluated. I think that if on the first img load there is an error (loading...) then the formatter is aborted
I may be wrong but I would suggest:
Do not use the dmx-bind:src
Pass the value of the image source as an argument/parameter to your javascript.
I suppose you need to fo that on the success event of your DataSourse (query or whatever...)
A simple layout with a column containing an img element (without dmx-bind:src)
I have an input and a button
I set the input.value to the source of the image I want
On button.click I run a function and pass the input.value as an argument:
function setImgSrc(imgsource) {
const current_image = document.getElementById('myImageID');
let imgSrc = current_image.setAttribute("src", imgsource);
}
This way I have no error...
Now, If instead of the above, I call the function setImgSrc(imgsource) on page load, even if a static value is set on the input, it would first through a 404 error and then show the image on page
Thanks for your time tasos, sorry about delay, was at cinema watching Deadpool and Wolverine.
Unfortunately the src value is only needed when the window resizes so this has to be a dynamic value as the purpose of the formatter is to change the image src as the view port changes.
Switching images is easy and works well and the formatter currently refreshes the full page on size change but that is not cosmetically nice.
So i want to refresh the image only, not the full screen hence needing to manage the src value.
To test for timing issue i wrapped the code in a 500ms setTimout()
setTimeout(function () {
console.log('refresh_id: ' + refresh_id)
console.log(document.getElementById('myImageID'))
var current_image = document.getElementById('myImageID')
var imgSrc = current_image.getAttribute('src')
console.log('Src is: ' + imgSrc)
}, 500)
}
and all works as it should
Thanks @Teodor for pointing me in the timing direction even if i blame the Wappler team for making AC2 so incredibly fast thus causing the timing issues
Also huge thanks to @famousmag for the time and effort he put into helping with this issue. You make a huge contribution to this forum and deserve praise my friend.