Search code examples
javascriptjqueryjquery-pluginsjquery-slider

jSlider jQuery plugin: Set a minimum range, and format minimum value?


I am using jSlider to implement a touch-friendly range slider, but I have two problems:

  1. I would like to set a minimum range of $10, but I don't seem to be able to do this. (In other words, there's always at least $10 between the lower and upper values.)
  2. I can't get the minimum value to format correctly as $0 - it's showing $ rather than $0 (actually I'd prefer it to be $1 but I can't implement that either).

I've set up a JSFiddle with my slider: http://jsfiddle.net/v3gUg/9/

Here is the code too, for reference:

var options = { 
  from: 0,
  to: 500,
  round: 10, 
  heterogeneity: ['50/100', '75/250'], 
  scale: ["£0", '|', "£50", '|' , "£100", '|', "£250", '|', "£500"],
  limits: true,
  step: 10,
  format: { format: '£#' }, // Doesn't return 0 correctly. 
  skin: "round_plastic",
  onstatechange: function() { 
      // Check range here and return false if too small?
      // But return false doesn't seem to do anything. 
     return false;
  }
};
jQuery("#price-slider").slider(options);

Can anyone suggest a solution to either problem?


Solution

  • EDIT:

           $(document).ready(function() { 
    
      var options = { 
          from: 0,
          to: 500,
          round: 10, 
          heterogeneity: ['50/100', '75/250'], 
          scale: ["$0", '|', "$50", '|' , "$100", '|', "$250", '|', "$500"],
          limits: true,
          step: 10,
          format: { format: '$#,' },
          skin: "round_plastic",
        callback: function() { 
          // if (range too small)
          //return false;
        },
      onstatechange: function( value ){
        var array = value.split(";");
    
        if(array[0] == array[1])
        {
          value = array[0]+";"+array[1];
          $(".holder").slider("value", p1, p2)
        }
      } 
        };
      jQuery("#price-slider").slider(options);
    
    });