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

Is there a way to detect out of limits values? #50

Open
pauloFernandes opened this issue Oct 18, 2016 · 5 comments
Open

Is there a way to detect out of limits values? #50

pauloFernandes opened this issue Oct 18, 2016 · 5 comments

Comments

@pauloFernandes
Copy link

Is there a way to detect if the user has set a value grater or lesser than slider's limit. For example, if my limits are 0-100, there's an event where I can say that the value is out of bounds, if the user sets 101?

@soundar24
Copy link
Owner

I can't get your requirement..
By general the user can't drag the handle out of range. So as per your example he can't drag to 101..
Are you mentioned that the user set through "setValue" ?
Can you describe more about your requirement for better understanding ..

@pauloFernandes
Copy link
Author

Yes.

My case occurs when the user clicks in the label (in the middle of the slider) and writes the value in the input. By doing this, the user can put any value (101 in the example). The slider does what is expected, and turns the value back to 100 - its limit.

I was wondering if there's a way to get notified if it happened because I need to notify the user that I have had to rollback the value written.

Thanks!

@soundar24
Copy link
Owner

Currently I have prepared a workaround to achieve your requirement. Check the below code, which needs to be included in your sample:

var _fn1 = $.fn.roundSlider.prototype._limitValue;
$.fn.roundSlider.prototype._limitValue = function (val) {
    var userValue = val;
    var modifiedValue = _fn1.call(this, val);
    var currentValue = this._handle1.value;
    var canUseModifiedValue = true;
    if (userValue !== modifiedValue) {
        canUseModifiedValue = this._raise("outOfRange", {
            userValue: userValue, modifiedValue: modifiedValue, currentValue: currentValue
        });
    }
    return canUseModifiedValue ? modifiedValue : currentValue;;
}

So when you enter a large value in the center textbox, it will raise an event outOfRange. In that event arguments you will get the required values, so based on that you can notify to the user. Also in that event if you return as "false" then it won't change the value.

Check the below demo, hopes it will helps you:

http://jsbin.com/fogewaj/edit?html,console,output

Check the demo and let me know your comments.

@pauloFernandes
Copy link
Author

Excellent! Works perfectly!!! It closes my issue.

@soundar24
Copy link
Owner

Good 👍 :) , so I will include this event in source level, in the next version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants