Search code examples
javascriptslidercurrencyprefixnouislider

noUiSlider prefix is not updating correctly


So I am using a noUiSlider for price selection. The handle values have a currency prefix, so I need to update it if a customer changes currency, naturally.

Here's my code:

priceSlider.noUiSlider.updateOptions({
  range: {
    min: minPrice,
    max: maxPrice
  },
  format: wNumb({ decimals: 0, prefix: currency })
})

Curiously, the range is being updated just fine, but the prefix is not being updated correctly. Is there something else I need to do to make this happen?


Solution

  • Here's how I ended up doing it:

    // Old prefix is different to new prefix, must destroy slider entirely
    if ((priceSlider.noUiSlider.get()).charAt(0) != currency) {
    
      priceSlider.noUiSlider.destroy()
      // Create new slider here
    
    } else {
    
      // Old prefix is identical, just do a regular update
      coursePriceSlider.noUiSlider.updateOptions({
        // options here
      })
    
    }