Slider range not setting handles properly
I'm trying to get jQueryUI Slider w/ two handles working (range). It keeps generating 8 slider handles instead of just two and they aren't being set to the initial values. ON change, I call ValSlider to get the values to update in the input box. I'm using data to pull the required settings into the slider function (I have to share this data w/ other scripts, so using this as easiest way), but I don't see any problems w/ doing that.
Here's a demo:
[ Removed ]
Here's the related simplified code for slider (range): (Tried to set up jsfiddle, but didn't have jqueryui )
- // call to set up slider & handle changes
- $('.slider').each(function() {
- var minvalue = parseInt($(this).attr('data-minval'), 10);
- var maxvalue = parseInt($(this).attr('data-maxval'), 10);
- var rangevalue = $(this).attr('data-rangeval');
- var stepvalue = parseInt($(this).attr('data-step'), 10);
- if (rangevalue == "true") {var valvalue = $(this).attr('data-val')}
- console.log('Valvalue: ' + valvalue);
- if (rangevalue == "true") { // multiple values
- $(this).slider({
- animate: 'fast',
- min: minvalue,
- max: maxvalue,
- range: rangevalue,
- step: stepvalue,
- values: valvalue,
- change: function(event, ui) {
- console.log('1Change: ' + ui.values[0] + ' 2Change: ' + ui.values[1]);
- $(this).prev().val(ui.values[0] + "-" + ui.values[1]);
- $(this).attr('data-change', 1);
- var mychange = ui.handle;
- console.log('Uihandle: ' , mychange);
- var slname = $(mychange).parent().attr('name');
- valSlider(slname,0)}
- });
- }
- });
- function valSlider(selname) {
- var myname = selname;
- console.log('valSlider - Slider name: ' + myname);
- if (myname == "init") { // set initial value
- // std form
- console.log('Inside init/std form');
- $('.slider').each(function() {
- // multiple values
- var sval = $(this).attr('data-val');
- sval = sval.replace(/\, /g,'-').slice(1, -1);
- console.log('Sval init/std: ' + sval);
- $(this).prev().val(sval);
- });
- }
- $('.slider').each(function() {
- var slch = $(this).attr('data-change');
- if (myname == "init") {return;} // don't run on init
- console.log('Slider Change: ' + slch);
- // indiv valuate
- if (slch == 0) {return;} // stop on unchanged indiv. sliders
- console.log('Indiv Valuate');
- var mythis = $('.slider[name="'+myname+'"]');
- console.log('Mythis: ' , mythis);
- console.log('Mythis-name: ' , mythis.attr('name'));
- console.log('Gen Val: ' + mythis.val());
- console.log(' Slider Val: ' + mythis.slider('values'));
- var slreq = 0;
- if (mythis.attr('required') || mythis.hasClass('ok')) {console.log('Slider Req'); slreq = 1}
- var slalert = 0;
- if (slch == 0) {console.log('SliderCheck is 0'); slalert = 1}
- if (slalert == 0 && slreq == 1) { // change req. to ok symbol
- console.log('Change to OK');
- mythis.removeAttr("required");
- mythis.addClass("ok");
- mythis.css({'border-color': '#cfd9db'});
- if (mythis.attr('data-rangeval') == "false") {var nval = mythis.val()}
- if (mythis.attr('data-rangeval') == "true") {
- var fval = mythis.slider('values', 0);
- var lval = mythis.slider('values', 1);
- var nval = fval + '-' + lval;
- }
- console.log('Slider val1: ' + fval + ' Slider val2: ' + lval);
- console.log('Slider val @ update: ' + nval);
- mythis.prev().val(nval);
- }
- });
- }
- valSlider('init',0);