Hi,

Any one know what's the easiest way to add a range selector (sildebar), that i can ask the users what are the price range you are looking for.

I thought this could be done with a cck filed module, but it seems it cant ;-(

thanks,
Tomer

(not really sure this is the right forum, but could find a better one)

Comments

Anonymous’s picture

Just create two int/text fields that will serve as FROM and TO and also another two hidden fields that will serve as MIN and MAX.
Hook the form and add a div that will serve as slider(or add it into the form itself if you are using your own).
Load jQ UI Slider via drupal_add_library('system', 'ui.slider');

And include some javascript like:

(function ($) {

  /**
   * Behaviors
   */
  Drupal.behaviors.category = {
    attach: function(context) {
    // Get values
    var price_from = $('input[name="price_from"]').val();
    var price_to = $('input[name="price_to"]').val();
    var price_min = $('input[name="price_min"]').val();
    var price_max = $('input[name="price_max"]').val();
    // Attach slider
    $('div.price-range').slider({
      range: true,
      min: parseInt(price_min),
      max: parseInt(price_max),
      values: [ price_from, price_to ],
      slide: function(event, ui) {
        $('input[name="price_from"]').val(ui.values[0]);
        $('input[name="price_to"]').val(ui.values[1]);
      }
    });
    // Bind autorefresh of values
    $('input[name="price_from"]').bind('keyup', function() {
      var from = $(this).val();
      var to = $('input[name="price_to"]').val();
      $('div.price-range').slider('option', 'values', [from, to]);
    });
    $('input[name="price_to"]').bind('keyup', function() {
      var from = $('input[name="price_from"]').val();
      var to = $(this).val();
      $('div.price-range').slider('option', 'values', [from, to]);
    });
  }
}

})(jQuery);

And this should be in Module development not in Theme development section.

tomer621’s picture

Although I must say that when i see such code I sort of turn green.

It's on my to learn list, once i finish mastering the "simple" use of drupal. btw, do you have any links to good leaning sources?

thanks again, for now i'll implement the fields you suggested,

Tomer