Slider not saving value correctly

115 views
Skip to first unread message

Drew Cranford

unread,
Nov 11, 2022, 3:47:13 PM11/11/22
to nodeGame
Hi Stefano,
I'm having an issue with the slider widget. The selected value is displaying correctly in the browser, and updates just fine as I move the slider. However, after finishing the step, the value saved in the memory.json is not the value that was selected. I can't seem to figure out where the value is coming from, as it appears to be randomly generated. Any insight or help would be greatly appreciated. And happy to provide you with more information, or even share my code.
Thank you,
Drew

shakty

unread,
Nov 11, 2022, 3:48:20 PM11/11/22
to nodeGame
Hi Drew,

Thanks for your email. Can you share your code?

Thanks,
Stefano

Message has been deleted

Drew Cranford

unread,
Nov 12, 2022, 4:42:59 AM11/12/22
to nodeGame
Yes, no problem.Gmail wouldn't allow me to attach any files here directly, but I've created a project on github and you should be able to access the code here:


-Drew

shakty

unread,
Nov 12, 2022, 4:57:42 AM11/12/22
to nodeGame
Hi,

I quickly checked your code:

  {
                        name: 'Slider',
                        id: 'confidence',
                        mainText: '2. How confident are you in your answer for question 1?',
                        texts: {
                            currentValue: function(widget, value) {
                                return '<datalist id="tickmarks" style="font-size: 14px"><option value="50" label="50"></option><option value="100" label="100"></option></datalist><datalist id="tickmarks" style="font-size: 12px"><option value="50" label="Not Confident at All"></option><option value="100" label="Fully Confident"></option></datalist>Confidence Level: ' + value;
                            }},
                        min: 50,
                        max: 100,
                        step: 5, //this doesn't actually do anything, instead it is created in the cb function
                        initialValue: 50,
                        displayNoChange: false,
                        required: true
                    }

Here is some explanations, that should also go into the wiki page for clarity.

What is inside texts: "xxx" is just for display, it is not returned by the .getValues method.
Your starting value is 50, end value is 100, and you have steps of 5. This means that you have in total 10 units in your slider: (100-50)/5. The slider goes always from 0 to 100, so each unit is valued 10.
When the slider is completely to the left, the display is 50, but the value is 0. If you move the slider one unit to the right, the display is 55, but the returned value is 10, the next displayed value is 60, and the next returned value is 20, and so on.
Hope it solves the mistery...

Best,
Stefano

Drew Cranford

unread,
Nov 14, 2022, 5:04:08 AM11/14/22
to nodeGame
Ok, I might have figured out my own problem. My min is 50 and max is 100. Is it therefore true then that the value returned is a percentage?
A silly oversight, if so. :)
-Drew

On Friday, November 11, 2022 at 3:48:20 PM UTC-5 shakty wrote:

shakty

unread,
Nov 14, 2022, 5:05:20 AM11/14/22
to nodeGame
The doc was not so clear to that regard, I have updated it now. If you have other issues do not hesitate to ask.

Best,
Stefano

Drew Cranford

unread,
Nov 14, 2022, 11:00:44 AM11/14/22
to nodeGame
Thanks Stefano,
A few comments on the updated documentation. Firstly, would it be clearer to describe the return value of 'value' as a percentage of the range between the min and max values? i.e., value = (currentValue-min)/(max-min)*100. This would allow people to easily compute the actual display value (currentValue) regardless of their min, max, and even step values. Which brings me to my second comment, in the example provided which comes from my code, there is a parameter called 'step' that I set to 5. However, that parameter doesn't actually do anything in the slider widget, so including it might confuse people. I actually had to add the code "W.getElementsByClassName('volume-slider')[0].setAttribute('step', '5');" to set the step attribute manually. However, I also believe that including 'step' as a parameter within the widget would be really useful to some people (like myself), and would be happy to see the option added in a future release/update. :)
Best,
Drew

shakty

unread,
Nov 14, 2022, 11:22:14 AM11/14/22
to nodeGame
Hi Drew,

Thanks for the feedback!

You are right about the "step" parameter, I got it wrong, it isn't implemented yet. But it's an easy change and I will include it now. However, it will come with the release of version 8, which I hope I will  happen in the next weeks.

Best,
Stefano

Reply all
Reply to author
Forward
0 new messages