Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2 working independent fields ? #542

Closed
st1mset opened this issue Mar 6, 2018 · 10 comments
Closed

2 working independent fields ? #542

st1mset opened this issue Mar 6, 2018 · 10 comments
Assignees
Labels
Discussion Discussing the topic Help wanted Person asking for help

Comments

@st1mset
Copy link

st1mset commented Mar 6, 2018

Do not tell me how to do it? I tried to do it like this, but in the end, one field controls both values

var $range = $(".js-range-slider"),
    $input = $(".js-input"),
    instance,
    min = 0,
    max = 4000;

$range.ionRangeSlider({
    type: "single",
    min: min,
    max: max,
    from: 0,
    onStart: function (data) {
        $input.prop("value", data.from);
    },
    onChange: function (data) {
        $input.prop("value", data.from);
    }
});

instance = $range.data("ionRangeSlider");

$input.on("change keyup", function () {
    var val = $(this).prop("value");
    
    // validate
    if (val < min) {
        val = min;
    } else if (val > max) {
        val = max;
    }
    
    instance.update({
        from: val
    });
});

var $range = $(".js-range-slider-to"),
    $inputTo = $(".js-input-to"),
    instance,
    min = 0,
    max = 2000;

$range.ionRangeSlider({
    type: "single",
    min: min,
    max: max,
    from: 0,
    onStart: function (data) {
        $inputTo.prop("value", data.from);
    },
    onChange: function (data) {
        $inputTo.prop("value", data.from);
    }
});

instance = $range.data("ionRangeSlider");

$inputTo.on("change keyup", function () {
    var val = $(this).prop("value");
    
    // validate
    if (val < min) {
        val = min;
    } else if (val > max) {
        val = max;
    }
    
    instance.update({
        from: val
    });
});
@IonDen
Copy link
Owner

IonDen commented Mar 6, 2018

Hi, simple. Second set of variables should be SECOND :) Now you just overwrite 1-st vars by new ones.

To avoid this, use unique names:

var $range_1 = $(".js-range-slider-1");
var $range_2 = $(".js-range-slider-2");

and so on for all other variables.

@IonDen IonDen self-assigned this Mar 6, 2018
@IonDen IonDen added Discussion Discussing the topic Help wanted Person asking for help labels Mar 6, 2018
@st1mset
Copy link
Author

st1mset commented Mar 7, 2018

did so, but that nothing has changed((

@IonDen
Copy link
Owner

IonDen commented Mar 7, 2018

I can't see what is wrong without a demo. Meanwhile, you can check this demo:
http://jsfiddle.net/IonDen/4k3d4y3s/

@st1mset
Copy link
Author

st1mset commented Mar 7, 2018

http://jsfiddle.net/4k3d4y3s/113/
As I said, if you enter the value in any of the fields, it changes with 2 sliders

@IonDen
Copy link
Owner

IonDen commented Mar 7, 2018

Be more careful with naming. You are saving both sliders in 1 instance variable:

instance = $range_1.data("ionRangeSlider");

You should have 2 instances

instance_1 = $range_1.data("ionRangeSlider");
instance_2 = $range_2.data("ionRangeSlider");

@st1mset
Copy link
Author

st1mset commented Mar 9, 2018

http://jsfiddle.net/4k3d4y3s/115/

Thanks, everything works, but that's just interesting why in 1 window you can not enter a value above 2000

@IonDen
Copy link
Owner

IonDen commented Mar 9, 2018

@st1mset, because you have max variable set 😄

max = 2000;

@st1mset
Copy link
Author

st1mset commented Mar 9, 2018

so this is for 2 variables, and the problem is related to the first

@IonDen
Copy link
Owner

IonDen commented Mar 9, 2018

@st1mset, no. This is for both, you again rewriting vars. You should have different max and min:
min_1, max_1, min_2, max_2

@st1mset
Copy link
Author

st1mset commented Mar 10, 2018

how it's complicated) thanks, work)

@IonDen IonDen closed this as completed Mar 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Discussion Discussing the topic Help wanted Person asking for help
Projects
None yet
Development

No branches or pull requests

2 participants