View Full Version : DomHelper: cannot create a label tag
e.e.coli
10-30-2006, 01:18 PM
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.
'for':'anything'
doesnt work?
e.e.coli
10-30-2006, 01:47 PM
Well, dip me in cornflour and deep fry me. It does work.
Excuse me, Jack, KuN, and all.
e.e.coli
10-30-2006, 02:50 PM
'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
10-30-2006, 02:59 PM
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
10-30-2006, 03: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
10-30-2006, 03:16 PM
I used the htmlFor patch. Thanks for posting it.
You are most welcome. It's a tiny drop in the ext bucket.
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.