Lulu
Lulu

Reputation: 81

How to Pass Values from a Double Handle jQuery Slider to a Rails Form

I'm using Slider Pips's double handled slider in a rails form. How do I pass the values from both slider handle locations to my rails controller as :min_sat and :max_sat? This is the JS file from Slider Pips.

This is the js

$(".element")
.slider({
    max: 1600,
    range: true,
    values: [1, 1600]
   }
})

.slider("pips", {
    rest: "label"
})

.slider("float");

and the html for the slider

<div class="element"></div>

Upvotes: 3

Views: 507

Answers (1)

simey.me
simey.me

Reputation: 2217

generally speaking you'd use the jquery-ui-slider method: .slider("values") (http://api.jqueryui.com/slider/#method-values) which will return you an array of values.


You can either do it on form-post:

$(".element").slider("values");

and then send that to a hidden form field, or send it via JSON to your controller.


or you could update a hidden form-field in real-time like:

$(".element").on("slide", function( ui ) {
    $("#formField").val( ui.values );
});

and then post that form normally, and your controller can take care of the rest.

Upvotes: 3

Related Questions