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 that you accept these cookies being set.

Circular-slider adding symbols
#1
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?
Reply
#2
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..
Reply
#3
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());
});
Reply
#4
Thank you admin! It works perfectly! Big Grin
Reply
#5
Is there a way to do the same thing with the +/- spinner?
Reply
#6
Probably not, because spinner uses numeric input field which will not accept this format.
Reply
#7
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
Reply
#8
You can try but this might break direct input. You will have to over-ride val function instead of text.
Reply


Forum Jump: