JavaScript noUiSlider - Get current slider in format or via update event

I have multiple sliders which is defined by document.querySelectorAll( '.js-slider' ); on tooltips.format I would like to insert a label above the value, which is defined on the current slide object via data-label.

On init this works fine.

But on update it gets the last initialized slider label, which is obvious :) But can I somehow get the current slider object or id inside the tooltips.format or inside the update event or get a hold of the settings object for the current slider?

var uiSlider = {
init : function() {
    var rangeInputs = document.querySelectorAll( '.js-slider' );
    uiSlider.setup( rangeInputs );
},
setup : function( sliders ) {
    var len = sliders.length,
        slider, min, max, step, value, range, start, postfix, pipValues, label, settings;

    function data( element , value ){
        return parseFloat( element.getAttribute( 'data-' + value ) );
    }

    while( len-- ) {            
        slider = sliders[len];                  
        min = data( slider,'min' );
        max = data( slider,'max' );
        step = data( slider,'step' );
        value = data( slider, 'value' );
        range = !isNaN( min ) && !isNaN( max ) ? { 'min': min, 'max': max } : { 'min': 0, 'max': 100 };
        start = !isNaN( value ) ? value : 0;
        postfix = slider.getAttribute( 'data-postfix' );
        pipValues = slider.getAttribute( 'data-pipvalues' ) ? slider.getAttribute( 'data-pipvalues' ).split( ',' ) : null;
        label =  slider.getAttribute( 'data-label' );
        settings = {
            start: start,
            step: !isNaN( step ) ? step : 1,
            connect: "lower",
            tooltips: {
                format: function( value, handle, settings ) {

                    var dformat = wNumb({
                        decimals: 0,
                        thousand: ',',
                        prefix: '<span class="noUi-tooltip__label">' + label + '</span>',
                        postfix: ( postfix ? ' ' + postfix : ' $' )
                    }); 

                    return dformat.to( parseFloat( value ) );
                }
            },
            range: range,
            pips: { // Show a scale with the slider
                mode: 'positions',
                values: pipValues ? pipValues : [ 0, 20, 40, 60, 80, 100 ],
                density: 2,
                format: wNumb({
                    decimals: 0,
                    thousand: ','
                })
            },
            format: wNumb({
                decimals: 0
            })
        };

        noUiSlider.create( slider, settings );

    }
}
};

uiSlider.init();

Havent been able to figure this out.

A running Fiddel of the problem can be seen here: Fiddle

Answer:1

How can i return array position of each object in an array. code let targets = [1.2, 2.3, 3.5]; let targetUpdatedOn = [2018-07-06, 2018-07-06, 2018-07-06]; let liveCoinPrice = 1.3; let targets_hit =...

How can i return array position of each object in an array. code let targets = [1.2, 2.3, 3.5]; let targetUpdatedOn = [2018-07-06, 2018-07-06, 2018-07-06]; let liveCoinPrice = 1.3; let targets_hit =...

I got an image in canvas. I need to scale my image to the top, to the bottom, to the left and to the right differently. Function drawImage has only width and height parameters, but not top, bottom, ...

I got an image in canvas. I need to scale my image to the top, to the bottom, to the left and to the right differently. Function drawImage has only width and height parameters, but not top, bottom, ...

I'm drawing a dashed line and a dashed rect in fabricjs, but there is an issue when setting the strokeWidth too high for the line/rect to draw the strokeDashArray properly. Example: if ...

I'm drawing a dashed line and a dashed rect in fabricjs, but there is an issue when setting the strokeWidth too high for the line/rect to draw the strokeDashArray properly. Example: if ...

I've recently started using Ramda to work with responses from JSONAPI and I am having some trouble dealing with complex relationships.. I have a big array with three smaller arrays, and I need to ...

I've recently started using Ramda to work with responses from JSONAPI and I am having some trouble dealing with complex relationships.. I have a big array with three smaller arrays, and I need to ...

  1. merge three arrays javascript
  2. merge three arrays php
  3. merge three arrays python
  4. merge three arrays
  5. merge three arrays java
  6. merge three arrays in js
  7. merge three arrays c#
  8. merge three sorted arrays
  9. numpy merge three arrays
  10. php merge three arrays into one
  11. merge three sorted arrays java
  12. jquery merge three arrays