I am experiencing in issue where in cases where I do not have an image that matches the data code no image is returned. I would like it so that my function checks if the file is there before appending it to the html - if it is not an actual image that I have available; I would like it to use one specific image.
Here is the code I have so far.
handleError: function(image) {
image.onerror = "";
image.src = "dog/dma/_resized/beagle.png";
return true;
},
tplItem: function(id, name, regional, national) {
var image_name = name.replace(',', '').replace(/\s/g, '').toLowerCase();
var image_html = '<div class="st-rounded-12 img overflow-hidden">' +
'<img src="' + this.imageDir + '/' + id + '/_resized/' + image_name + '.jpeg" alt="" onerror="handleError(this);">' +
'</div>';
return '<div class="columns shrink">' +
'<div class="breeds-chart-wrapper flex-container align-bottom align-center">' +
'<div class="breeds-chart">' +
image_html +
'<div class="flex-container align-bottom align-center line-chart-wrapper">' +
'<div class="line-chart text_22_32 font_avenir_roman font-weight-bold bg-red-light color-red-light" style="height: calc(25vh/100 * ' + regional + ')">' +
'<span class="text">' + regional + '%</span>' +
'</div>' +
'<div class="line-chart text_22_32 font_avenir_roman font-weight-bold bg-green color-green" style="height: calc(25vh/100 * ' + national + ')">' +
'<span class="text">' + national + '%</span>' +
'</div>' +
'</div>' +
'</div>' +
'</div>' +
'<div class="text-center chart-text text_22_32 color-aluminium font_avenir_roman font-weight-bold">' + name + '</div>' +
'</div>';
onloadevent of the image