Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > Limitations on dataset types

Reply
Thread Tools

Limitations on dataset types

 
 
Tim Streater
Guest
Posts: n/a
 
      06-14-2012
I just wasted an hour until I remembered that the dataset variables in
HTML5 have to be integers. Anyone know why there is this limitation?

I had ptr as a pointer to an <li> element, and couldn't figure out why:

if (ptr.dataset.myflag==true) return;

was not being executed even though myflag had been set to true earlier
(and I used console.info() to confirm it). All started to work as
expected when I changed to use 0 and 1 instead of false and true.

--
Tim

"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted" -- Bill of Rights 1689
 
Reply With Quote
 
 
 
 
Jukka K. Korpela
Guest
Posts: n/a
 
      06-14-2012
2012-06-14 22:31, Tim Streater wrote:

> I just wasted an hour until I remembered that the dataset variables in
> HTML5 have to be integers. Anyone know why there is this limitation?


There is no such limitation.

> if (ptr.dataset.myflag==true) return;
>
> was not being executed even though myflag had been set to true earlier


You cannot set it to the truth value true in HTML markup. If you have

<li data-myflag="true">

or, equivalently,

<li data-myflag=true>

then you are setting the value to the string "true". You can check this
in JavaScript by displaying typeof(ptr.dataset.myflag).

And in JavaScript, even the "==" operator, which tests for an
equality-like relation, does not treat the truth value true and the
string value "true" as identical.

So you would need to test ptr.dataset.myflag == "true" or
ptr.dataset.myflag === "true".

As a different issue, such a way of accessing data-* variables is not
supported by all browsers (see http://caniuse.com/dataset), so it would
be safer to test for

ptr.getAttribute('data-myflag') === "true"

--
Yucca, http://www.cs.tut.fi/~jkorpela/
 
Reply With Quote
 
 
 
 
Tim Streater
Guest
Posts: n/a
 
      06-14-2012
In article <jrdgfr$pmp$>,
"Jukka K. Korpela" <> wrote:

> 2012-06-14 22:31, Tim Streater wrote:
>
> > I just wasted an hour until I remembered that the dataset variables in
> > HTML5 have to be integers. Anyone know why there is this limitation?

>
> There is no such limitation.


OK, I looked here:

<http://www.w3.org/TR/2009/WD-html5-20090423/dom.html>

(whether this is the correct place I know not) and there is no explicit
mention of types, although I guess, as you say below, that values have
to be settable via HTML, which would preclude boolean values.

> > if (ptr.dataset.myflag==true) return;
> >
> > was not being executed even though myflag had been set to true earlier

>
> You cannot set it to the truth value true in HTML markup. If you have
>
> <li data-myflag="true">
>
> or, equivalently,
>
> <li data-myflag=true>
>
> then you are setting the value to the string "true". You can check this
> in JavaScript by displaying typeof(ptr.dataset.myflag).
>
> And in JavaScript, even the "==" operator, which tests for an
> equality-like relation, does not treat the truth value true and the
> string value "true" as identical.
>
> So you would need to test ptr.dataset.myflag == "true" or
> ptr.dataset.myflag === "true".
>
> As a different issue, such a way of accessing data-* variables is not
> supported by all browsers (see http://caniuse.com/dataset), so it would
> be safer to test for
>
> ptr.getAttribute('data-myflag') === "true"


In fact I'm not setting it in HTML. I'm setting it in JavaScript, as in:

ptr.dataset.myflag = true;

(but now using integers instead, as I mentioned). So I wonder what that
actually sets it to.

I control which browser gets used (Safari, in this case).

--
Tim

"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted" -- Bill of Rights 1689
 
Reply With Quote
 
Jukka K. Korpela
Guest
Posts: n/a
 
      06-14-2012
2012-06-14 23:49, Tim Streater wrote:

> OK, I looked here:
>
> <http://www.w3.org/TR/2009/WD-html5-20090423/dom.html>
>
> (whether this is the correct place I know not)


HTML5 is work in progress, not a specification, but it is better to
consult the newest drafts, like http://www.w3.org/TR/html5/ or the
WHATWG "Living Standard"
http://www.whatwg.org/specs/web-apps...ork/multipage/
(The URL you mention refers to a draft that is over three years old.)

> and there is no explicit
> mention of types, although I guess, as you say below, that values have
> to be settable via HTML, which would preclude boolean values.


When no restriction has been set, an attribute value is any string. HTML
attribute values are always strings from the JavaScript perspective; to
use them as other than string, they need to be type-converted,
implicitly or explicitly.

> In fact I'm not setting it in HTML. I'm setting it in JavaScript, as in:
>
> ptr.dataset.myflag = true;


It seems that the dataset property behaves somewhat oddly: the above
assigns the string "true", not the truth value true. Here, too,
displaying typeof(ptr.dataset.myflag) shows that it is a string.

So it would be better to set it to "true" and do the test accordingly.

--
Yucca, http://www.cs.tut.fi/~jkorpela/
 
Reply With Quote
 
Tim Streater
Guest
Posts: n/a
 
      06-15-2012
In article <jrdl47$nev$>,
"Jukka K. Korpela" <> wrote:

> 2012-06-14 23:49, Tim Streater wrote:
>
> > OK, I looked here:
> >
> > <http://www.w3.org/TR/2009/WD-html5-20090423/dom.html>
> >
> > (whether this is the correct place I know not)

>
> HTML5 is work in progress, not a specification, but it is better to
> consult the newest drafts, like http://www.w3.org/TR/html5/ or the
> WHATWG "Living Standard"
> http://www.whatwg.org/specs/web-apps...ork/multipage/
> (The URL you mention refers to a draft that is over three years old.)


Well I knew *that* , but it was late and it was the best I could come
up with quickly.

> > and there is no explicit
> > mention of types, although I guess, as you say below, that values have
> > to be settable via HTML, which would preclude boolean values.

>
> When no restriction has been set, an attribute value is any string. HTML
> attribute values are always strings from the JavaScript perspective; to
> use them as other than string, they need to be type-converted,
> implicitly or explicitly.
>
> > In fact I'm not setting it in HTML. I'm setting it in JavaScript, as in:
> >
> > ptr.dataset.myflag = true;

>
> It seems that the dataset property behaves somewhat oddly: the above
> assigns the string "true", not the truth value true. Here, too,
> displaying typeof(ptr.dataset.myflag) shows that it is a string.


Well I'll be hornswoggled.

> So it would be better to set it to "true" and do the test accordingly.


Er possibly but I'm done with that code for the moment. Anyway - thanks
for the useful clarifications.

--
Tim

"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted" -- Bill of Rights 1689
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Putting logical limitations on types Ido Yehieli C Programming 27 01-28-2008 03:50 PM
DataSet and dataSet JimO ASP .Net 2 03-08-2006 02:39 PM
copying a datatable content from an untyped dataset into a table which is inside a typed dataset Nedu N ASP .Net 2 10-31-2003 01:05 PM
Ccopying a datatable content from an untyped dataset into a table which is inside a typed dataset Nedu N ASP .Net 1 10-31-2003 02:39 AM
DataSet to DataSet Joseph D. DeJohn ASP .Net 1 08-04-2003 03:25 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57