Logic Machine Forum
Circular-slider adding symbols - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Visualization (https://forum.logicmachine.net/forumdisplay.php?fid=9)
+--- Thread: Circular-slider adding symbols (/showthread.php?tid=594)



Circular-slider adding symbols - Mirco - 06.02.2017

Hi guys, I know that I annoying you with my strange questions but I need your help! Wink 

I have a circular slider that controls a 1 byte integer that that have a limited range +-3, now my problem is that I would like to display the plus symbol (+) before the number when it is greater than zero, like it happened with the minus symbol (-) when the number is lower than zero.

I tryed to write some javascript code but nothing worked.. Can someone help me?


RE: Circular-slider adding symbols - Mirco - 06.02.2017

I almost solved it with this code:
Code:
$('.example .circularslider-max').on("vclick", function() {
   setTimeout(function() {
     var val = $('.example .circularslider-value').text();
     if (val == "1" || val == "2" || val == "3")
     {
       val = "+" + val;
       $('.example .circularslider-value').text(val);
     }
   }, 120);
 });

But it doesn't work really well because sometimes the other script overwritten the value..


RE: Circular-slider adding symbols - admin - 06.02.2017

Try this:
Code:
$(function(){
  var el = $('.example > div').data('circularslider').$value
      , fn = el.text;
  
  el.text = function(v) {
    if (typeof v != 'undefined') {
      if (parseInt(v, 10) > 0) {
        v = '+' + v;
      }
      return fn.call(el, v);
    }
    else {
      return fn.call(el);
    }
  }

  el.text(el.text());
});



RE: Circular-slider adding symbols - Mirco - 06.02.2017

Thank you admin! It works perfectly! Big Grin


RE: Circular-slider adding symbols - Mirco - 06.02.2017

Is there a way to do the same thing with the +/- spinner?


RE: Circular-slider adding symbols - admin - 06.02.2017

Probably not, because spinner uses numeric input field which will not accept this format.


RE: Circular-slider adding symbols - Mirco - 07.02.2017

Even if I force the spinner to be type = "text", with this code?

Code:
$('.example .spinner-value').attr('type', 'text');

I would like to put a zero (0) before the value when it is between 0 and 10


RE: Circular-slider adding symbols - admin - 07.02.2017

You can try but this might break direct input. You will have to over-ride val function instead of text.