- Solved -
I Know they exist, but I haven't found a slider that can easily meet some very basic needs and I'm sure I'm not the only one frustrated with this problem. This is what I have so far. Am I heading in the right direction?
What I'm Trying to Do:
Using the JQuery UI slider, I need multiple sliders on the page. Each slider will have a min of 0, a dynamic max, and a dynamic default value. I set these values in an input field with the html elements min, max, value and retrieve them later through javascript / jquery.
In addition to their individual max values, there also needs to be a total max value that the sum of all sliders cannot exceed. Finally, I also need availability to update the slider from the input box (as well as the slider itself).
What I have so Far:
After researching a number of sliders, I settled on using the JQuery UI slider and eventually came across this post that got me started with reaching my goals: Combined total for multiple jQuery-UI Sliders
I altered the code to (1) Use a hidden input field to retrieve total max value; (2) populate an input text field instead of a span with the current value; (3) set the individual slider's initial max value from the max= attribute; (4) set the slider to disabled: true if the initial max is 0; and (5) listen for changes to the text box and move the slider according to number entered if it will not exceed the max value.
Current Code (JSFiddle): (see the jsfiddle in answer)
(Slider #1 Initial max is 0 - disabled // Other Sliders have max of 500 // total table max is 1000)
What the Slider is Doing Right:
- It adjusts nicely and stays under the total max limit correctly
- Sets the initial individual max and total max correctly
- Sets and stays disabled when the max is 0
- Slides correctly when you change the text box
What I Need Help / Ideas on Fixing:
- Changing the sliders tends to change the individual slider max = the total max
- Changing the text box slides the current bar correctly, but doesn't update the other sliders to keep them from going over total max
- I am currently using the .focusout() event on the text boxes because .change() causes it to go crazy b/c the slider is also changing the text box.
Let me know what you think.
UPDATE:
I was sad not to hear any responses, but I think I cracked it. Needed to limit reliability on that original code and mostly rewrite. I will submit my solution as an answer below. Please try it out and let me know what you think. This was quite a process, so hopefully someone finds this useful :)