Page 1 of 1

Change image icon

Posted: Saturday 22 June 2019 11:17
by HansieNL
I got a text block with Buienradar info.

Code: Select all

blocks[345] = {} //Buienradar (text)
    blocks[345]['title'] = 'Buienradar';
    blocks[345]['switch'] = true;
    blocks[345]['width'] = 12;
    blocks[345]['image'] = '../custom/img/rain-off.png';

Code: Select all

function afterGetDevices(){
  // Buienradar
  if (alldevices[345].Data == 'Voorlopig droog') {
    $('.block_345 .col-icon').addClass('off-ico');
    $('.block_345 .col-data').addClass('off-stat');
  }
  else {
    $('.block_345 .col-icon').removeClass('off-ico');
    $('.block_345 .col-data').removeClass('off-stat');
  }
Image
I wanna also change the image icon if the text is not "Voorlopig droog". Can someone tell me how to get this done?
Thanks in advance.

Re: Change image icon

Posted: Thursday 18 July 2019 18:43
by Lokonli
HansieNL wrote: Saturday 22 June 2019 11:17 I got a text block with Buienradar info.

Code: Select all

blocks[345] = {} //Buienradar (text)
    blocks[345]['title'] = 'Buienradar';
    blocks[345]['switch'] = true;
    blocks[345]['width'] = 12;
    blocks[345]['image'] = '../custom/img/rain-off.png';

Code: Select all

function afterGetDevices(){
  // Buienradar
  if (alldevices[345].Data == 'Voorlopig droog') {
    $('.block_345 .col-icon').addClass('off-ico');
    $('.block_345 .col-data').addClass('off-stat');
  }
  else {
    $('.block_345 .col-icon').removeClass('off-ico');
    $('.block_345 .col-data').removeClass('off-stat');
  }
Image
I wanna also change the image icon if the text is not "Voorlopig droog". Can someone tell me how to get this done?
Thanks in advance.
Try the following:

You can change the image by adding the following function to custom.js:
(it works for a normal switch. I did not test with a text block)

Code: Select all

function getStatus_345(idx,value,device){
	if (device.Data == 'Voorlopig droog') {
	
		blocks[345]['image'] = 'blinds_open.png'
	 }
	 else {
		blocks[345]['image'] = 'blinds_closed.png'
	 }
 }

Re: Change image icon

Posted: Friday 19 July 2019 18:59
by HansieNL
Thanks a lot. Thanks again.