question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Slider with % AND dynamic value - can't seem to get prettify to work

See original GitHub issue

I have an existing slider with data attributes like this:

min: 0, max: 100, step: 1, postfix: '%'

I would like to have the slider display like this (I manually edited the HTML to show this):

Screen Shot 2021-02-27 at 1 22 08 PM

The page has multiple sliders in a nested form so each has an associated base multiplier amount i.e. $10,000 x 50% and the slider handle would dynamically update.

My thought here is that I do this:

min: 0, max: 100, step: 1, value: 10000

then I tried this:

$(".myclass").ionRangeSlider()({
  min: 0,
  max: 100,
  step: 1,
  value: $(this).data('value'),
  prettify: function(n) {
    return n + '%' + ' ($' + value * n / 100 + ')';
  }
});

and get:

Screen Shot 2021-02-27 at 2 12 27 PM

I will admit to not being the most proficient at JS so I may be missing something minor / obvious here. After some digging I think I am not accessing the value data attribute. I also tried this (and realized I need to turn my string to a float):

$(".myclass").ionRangeSlider()({
  min: 0,
  max: 100,
  step: 1,
  prettify: function(n) {
    return n + '%' + ' ($' + parseFloat($(this).data('value')) * n / 100 + ')';
  }
});

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
IonDencommented, Mar 3, 2021

Yes, I will think about it.

0reactions
aximusengcommented, Mar 4, 2021

I ended up settling on this (bac is my data attribute value):

$('.js-range-slider').each(function() {
  var bac;
  bac = parseFloat($(this).data('bac'));
  return $(this).ionRangeSlider({
    prettify: function(n) {
      var current;
      current = Math.round(bac / 100 * n);
      return n + '%' + ' ($' + current + ')';
    }
  });
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

VS-Code Prettier Format On Save doesn't work - Stack Overflow
Follow these steps: CTRL + SHIFT + P; Format Document (in pop-up bar); Select Format Document; Select Configure Default Formatter.
Read more >
Slider not working with dynamic values. #985 - GitHub
Slider (p-slider) is working fine with dynamic values like this But when ... When It's at the left end, the value should be...
Read more >
Options - Prettier
Prettier's printWidth option does not work the same way. It is not the hard upper allowed line length limit. It is a way...
Read more >
What is a Layer and How to Use it in Smart Slider 3?
Transition layers can be used to make the slides prettier, and more interactive. This layer has two image fields where you can set...
Read more >
How to configure Prettier and VSCode - Gleb Bahmutov
To use the Prettier we have just installed from VSCode we need to install ... like ESLint can catch the assignment to a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found