YUILibrary - Open source JavaScript and CSS for building richly interactive software.
Fork YUI on GitHub
  [ 3 posts ]

Marco Asbreuk

  • Username: itsasbreuk
  • Joined: Mon Nov 16, 2009 5:14 am
  • Posts: 76
  • Location: Netherlands
  • GitHub: Marco Asbreuk
  • Gists: Marco Asbreuk
  • IRC: ITSAsbreuk
  • Offline
  • Profile

Why doesn't the slider accept my json-parsed conf-object

Post Posted: Mon Jul 26, 2010 3:59 am
+0-
Does anybody know why my conf-object isn't accepted well by the slider?
I created 2 sliders with a conf-object.

1: object that is transformed through json and passed to slider1. In the console you can see that the jsonobject seems right configured. But only the value is accepted by the slider. Not min and max.
2: the same object, but now created from scratch and passed into slider2. Here the object is accepted well.

In the example, the console gives information about what happened.

Here is the full code:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Basic Sliders</title>
<link type="text/css" rel="stylesheet" href="http://yui.yahooapis.com/3.1.1/build/cssfonts/fonts-min.css" />
<script type="text/javascript" src="http://yui.yahooapis.com/3.1.1/build/yui/yui-min.js"></script>
</head>

<body class="yui3-skin-sam  yui-skin-sam">
    <p>
        <span id="horiz_slider1"></span><br />
        <span id="horiz_slider2"></span><br />
    </p>

<script type="text/javascript">
// Create a YUI instance and request the slider module and its dependencies
YUI().use("slider", "json-parse", 'console', function (Y) {
    new Y.Console({height:400}).render();
   
    // first slider 1: min and max are not accepted
    var jsoncfg = '{"min":"-50","value":"40","max":"50"}';
    var cfgobj1 = Y.JSON.parse(jsoncfg);
    var slider1 = new Y.Slider(cfgobj1).render('#horiz_slider1');

    // next slider 2: this conf-object works well
    var cfgobj2 = {min:-50,value:40,max:50};
    var slider2 = new Y.Slider(cfgobj2).render('#horiz_slider2');

    // now some logging to see what happens
    Y.log('json cfgobj1.value: '+cfgobj1.value, 'warn', 'cfgobj1');
    Y.log('json cfgobj1.min: '+cfgobj1.min, 'warn', 'cfgobj1');
    Y.log('json cfgobj1.max: '+cfgobj1.max, 'warn', 'cfgobj1');
    Y.log('slider1.value: '+slider1.get("value"), 'error', 'slider1');
    Y.log('slider1.min: '+slider1.get("min"), 'error', 'slider1');
    Y.log('slider1.max: '+slider1.get("max"), 'error', 'slider1');
    Y.log('slider2.value: '+slider2.get("value"), 'info', 'slider2');
    Y.log('slider2.min: '+slider2.get("min"), 'info', 'slider2');
    Y.log('slider2.max: '+slider2.get("max"), 'info', 'slider2');

});
</script>

</body>
</html>

Marco.

Luke Smith

YUI Developer

  • Username: lsmith
  • Joined: Thu Aug 28, 2008 7:50 am
  • Posts: 237
  • Location: Sunnyvale
  • Twitter: ls_n
  • GitHub: lsmith
  • Gists: lsmith
  • IRC: ls_n
  • YUI Developer
  • Offline
  • Profile

Re: Why doesn't the slider accept my json-parsed conf-object

Post Posted: Mon Jul 26, 2010 7:52 am
+0-
In the parsed JSON case, you are passing numeric strings as the values, not numbers as you are in the cfgobj2. Slider expects numbers for min and max. The value assignment goes through a setter which happens to coerce numeric strings to true numbers.

You're welcome to submit an enhancement request for numeric string support for min and max. Or just pass numbers.

Code:
var jsoncfg = '{"min":-50,"value":40,"max":50}';
...

Marco Asbreuk

  • Username: itsasbreuk
  • Joined: Mon Nov 16, 2009 5:14 am
  • Posts: 76
  • Location: Netherlands
  • GitHub: Marco Asbreuk
  • Gists: Marco Asbreuk
  • IRC: ITSAsbreuk
  • Offline
  • Profile
Tags:

Re: Why doesn't the slider accept my json-parsed conf-object

Post Posted: Mon Jul 26, 2010 8:19 am
+0-
Luke,

No enhancement request needed: its a good way to force numberic values when needed.
I should have been more careful about this. I missed it though, because the value was accepted.

Thx for helping me out!

Regards,
Marco.
  [ 3 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum