Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to remove the decimals on noUiSlider? #165

Open
msbt opened this issue Mar 31, 2020 · 11 comments · May be fixed by #206
Open

How to remove the decimals on noUiSlider? #165

msbt opened this issue Mar 31, 2020 · 11 comments · May be fixed by #206

Comments

@msbt
Copy link

msbt commented Mar 31, 2020

I tried editing the json file, but no dice... Any pointers on how I can remove the .00 decimals on a rangeslider? I have a slider that should only show integers (like how many people are coming to that event). I'm trying to implement that in WordPress, so a general solution would be nice.

Example: https://www.surveyjs.io/Examples/Library/?id=custom-widget-nouislider

Best regards,
Matthias

@tsv2013
Copy link
Member

tsv2013 commented Mar 31, 2020

At this moment there is no such an option for the noUiSlider custom widget. We need to implement it in the widget source code - https://github.com/surveyjs/widgets/blob/master/src/nouislider.js#L80-L90

I've added this enhancement in our task list

@msbt
Copy link
Author

msbt commented Mar 31, 2020

ok cool, in the meantime I just added tooltips: wNumb({decimals: 0}), to get rid of the decimals

@tsv2013
Copy link
Member

tsv2013 commented Apr 1, 2020

Did you modify the nouislider custom widget source code?

@msbt
Copy link
Author

msbt commented Apr 1, 2020

no, the surveyjs/libs/surveyjs-widgets.js file, that part here:

      var slider = __WEBPACK_IMPORTED_MODULE_0_nouislider___default.a.create(el, {
        start: question.value || (question.rangeMin + question.rangeMax) / 2,
        connect: [true, false],
        step: question.step,
        tooltips: wNumb({decimals: 0}),
        pips: {
          mode: question.pipsMode || "positions",
          ...

and this is how it looks:
grafik

@tsv2013
Copy link
Member

tsv2013 commented Apr 1, 2020

Did you add the wnumb library? - https://refreshless.com/wnumb/

@msbt
Copy link
Author

msbt commented Apr 1, 2020

yes

@johannesschobel
Copy link
Contributor

Dear @tsv2013 and @msbt ,

i think, the issue is also with the data value of respective slider. Currently, the slider returns "4.00" (as string) in your example. However, you may want to have 4 (as number).

I fixed it via

slider.on("change", function() {
  question.value = wNumb({decimals: 0}).from(slider.get());
});

in the same file, however, this is not a permanent fix (as the file is updated with every npm install again).

Can we support the format option of the nouislider described here https://refreshless.com/nouislider/number-formatting/ ?

All the best

@johannesschobel
Copy link
Contributor

Maybe the even better fix would be to just cast it to a number?
Like so:

slider.on("change", function() {
  question.value = Number(slider.get());
});

@tsv2013
Copy link
Member

tsv2013 commented May 30, 2020

We can't add a hard cast in our code because other users can use the float numbers. But you can modify the question value in the https://surveyjs.io/Documentation/Library?id=surveymodel#onValueChanging event handler

@johannesschobel
Copy link
Contributor

But casting it with Number(value) would certainly work, because currently it is a decimal number formatted as string, right?!

@johannesschobel
Copy link
Contributor

Can we have some kind of hook to format the visual output (i.e. the number shown next to the handle)?

And if that is not possible, maybe just a numeric input field to enter the number of decimals to be shown (i.e. "0" would remove the decimals completely). Internally you could rely on wNumb() as discussed above..

@MrKrabat MrKrabat linked a pull request Aug 5, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants