This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

Set a value when a widget come up
#1
Hi, as in the Thread subjet I need to set an object's value (unsigned Integer) when a widget pops up.

Can you help me?

Thanks

Peppe
Reply
#2
You can use this example. Set Additional classes to widget-open for the element that opens the widget. #widget-2 is widget element id, change it and group address as needed.
Keep in mind that it won't work when transition animation is enabled.
Code:
$(function() {
  $('.widget-open').on('vclick', function() {
    var el = $('#widget-2');
    if (el.is(':visible')) {
      grp.write('1/1/1', 123);
    }
  });
});

There will be widget show/hide events added in RC2 firmware that will work correctly with animation:
Code:
$(function() {
  $('#widget-2').on('widget-show', function() {
    grp.write('1/1/1', true);
  });
  
  $('#widget-2').on('widget-hide', function() {
    grp.write('1/1/1', false);
  });
});
Reply
#3
(22.03.2020, 14:34)admin Wrote: You can use this example. Set Additional classes to widget-open for the element that opens the widget. #widget-2 is widget element id, change it and group address as needed.
Keep in mind that it won't work when transition animation is enabled.
Code:
$(function() {
  $('.widget-open').on('vclick', function() {
    var el = $('#widget-2');
    if (el.is(':visible')) {
      grp.write('1/1/1', 123);
    }
  });
});

There will be widget show/hide events added in RC2 firmware that will work correctly with animation:
Code:
$(function() {
  $('#widget-2').on('widget-show', function() {
    grp.write('1/1/1', true);
  });
 
  $('#widget-2').on('widget-hide', function() {
    grp.write('1/1/1', false);
  });
});


Ok thanks but... how I can get the actual WIDGET ELEMENT ID?
Reply
#4
Open visualization in your browser, open the widget, right click in any empty space inside your widget and select "inspect element". In HTML inspector you will see something like <div id="widget-2"... widget-2 is your widget ID. Make sure that selector in Custom JS has # in the selector before the ID: $('#widget-2');
Reply
#5
Ok! Everything is working... thanks!

Peppe
Reply
#6
Just to make it perfect: How I can make a widget pop when when some grp address is triggered?

like you made for a plan with the code  below:


$(function(){

  if (typeof objectStore !== 'undefined') {

    var id = Scada.encodeGroupAddress('1/1/2');



    objectStore.addListener(id, function(object, type) {

      if (type == 'value') {

        showPlan(69);

      }

    });

  }

});





Tnx
Reply
#7
Have you seen this?
https://forum.logicmachine.net/showthrea...34#pid1934
Reply
#8
(23.03.2020, 11:50)Daniel. Wrote: Have you seen this?
https://forum.logicmachine.net/showthrea...34#pid1934
yes... it seems it doesn't work   Sad
Reply
#9
There's an easier way to show a widget by simulating a click on the element that opens it. Make sure that your sending script is not attached to the same element otherwise you will get a loop.

Here, when 1/1/1 value is true view is switched to plan 12 and if #widget-2 is not yet shown a click event is triggered on an element with class show-widget
Code:
$(function() {
  if (typeof grp == 'object') {
    grp.listen('1/1/1', function(obj, state) {
      if (state == 'value' && obj.value) {
        showPlan(12);

        if (!$('#widget-2').is(':visible')) {
          $('.show-widget').click();
        }
      }
    });
  }
});
Reply


Forum Jump: