PDA

View Full Version : DomHelper: cannot create a label tag



e.e.coli
30 Oct 2006, 10:18 AM
Captain, I canna


dh.append(myThang, {tag: 'label, for: 'anything'});

because 'for' is a reserved word, but is also a required attribute for a label tag.

Cheers.

KuN
30 Oct 2006, 10:36 AM
'for':'anything'
doesnt work?

e.e.coli
30 Oct 2006, 10:47 AM
Well, dip me in cornflour and deep fry me. It does work.

Excuse me, Jack, KuN, and all.

e.e.coli
30 Oct 2006, 11:50 AM
'for':'anything'
doesnt work?

Ach, in fact it does not work... in IE 6 and in an older Firefox. "for" is indeed a reserved word, and is not permitted as a property identifier in an object.

Jack, if you're reading this, my current workaround is to patch DomHelper something like



if(attr == 'cls'){
b += ' class="' + o['cls'] + '"';
}else if(attr == 'forfield'){
b += ' for="' + o[attr] + '"';
}else{
b += ' ' + attr + '="' + o[attr] + '"';
}



and



if(attr=='cls'){
el.className = o['cls'];
}else if (attr=='forfield') {
el.htmlFor = o['forfield'];
}else{
if(useSet) el.setAttribute(attr, o[attr]);
else el[attr] = o[attr];
}


I'm not advocating for "forfield" as a "good" solution; I trust your aesthetics about that.
Cheers.

e.e.coli
30 Oct 2006, 11:59 AM
Better yet, if you use
htmlFor as the special property, you only have to patch the html gen side, not the dom side.

jack.slocum
30 Oct 2006, 12:13 PM
I have never run into an error using 'for', but it doesn't surprise me that it could throw an error.

I used the htmlFor patch. Thanks for posting it.



...
if(attr == 'cls'){
b += ' class="' + o['cls'] + '"';
}else if(attr == 'htmlFor'){
b += ' for="' + o['htmlFor'] + '"';
}else{
b += ' ' + attr + '="' + o[attr] + '"';
}
...

e.e.coli
30 Oct 2006, 12:16 PM
I used the htmlFor patch. Thanks for posting it.

You are most welcome. It's a tiny drop in the ext bucket.