DomHelper Template using tables (bug in ff & insert at t
I have 2 issues one seems to be a bug in firefox when using compiled templates and the 2nd is a question of the best way to insert a tr at the top of a table. I am using both the latest copy of yui and yui-ext.
Issue 1:
I am using the YAHOO.ext.DomHelper library to add a tr to a table. I have noticed that there is an exception in firefox when using the following code. If I do not compile teh template it works fine.
Code:
<script>
var id = 3;
function addProfile() {
var tplNode = document.getElementById('profile-template');
var tpl = new YAHOO.ext.DomHelper.Template(tplNode.innerHTML);
tpl.compile();
tpl.append('profile-table', {profilename: 'My Profile', id: id});
id++
}
</script>
<input type="button" onClick="addProfile();" value="Add a Profile">
<table>
<tbody id="profile-table">
<tr id="profile1"><td>Profile 1</td></tr>
<tr id="profile2"><td>Profile 2</td></tr>
</tbody>
</table>
<div style="display:none" id="profile-template">
<tr id="profile{id}">
<td>{profilename} {id}</td>
</tr>
</div>
The error is
Error: unterminated string literal
Source File: Desktop/test/javascripts/yahoo/yui-ext.js
Line: 183, Column: 42
Source Code:
this.compiled = function(values){ return ['
Issue 2:
I noticed that I needed to explicitly define a tbody tag and give it an id to get things to work (instead of giving an id to the table). My question is what is the best way to insert a tr at the top of the table. insertAfter will actually insert it after the tbody tag and of course it doesn't render. append will add it successfully to the end of the table.
thx for the quick response
Jarred -
Thanks for the quick response on the newlines in the template html. This fixes the firefox compilation issue. It also fixes the same issue in the latest version of Opera.
Aaron
Does anyone have any ideas on the easiest way to insertRow(0) other than retrieving the top most row id and using 'insertBefore'?