PDA

View Full Version : Turn off HTML markup


kbriggs
03-28-2008, 11:51 AM
Is there an easy way to turn off HTML markup in the various components that display text, especially a grid with gridtext? If I have user data with something like "<b>", I want it to show it as-is with the angled brackets, not bolding the text. It would be nice is there was something like a markup="false" attribute.

When setting a text view via script, I can run it through an escape function like this:


function HTML_Escape(t)
{
return t.split("&").join("&amp;").split("<").join("&lt;").split(">").join("&gt;");
}


But I haven't figured out how to intercept the text going to a grid via gridtext.

rcyeager
03-28-2008, 12:06 PM
There is no built-in way that I know of to turn off HTML text behavior. Maybe file a Jira request for that.

For the gridtext issue, one way is to escape the text in the dataset before feeding it into the grid. Another way is to intercept the ondata event for the gridtext and manipulate the data there, if you want to manipulate the data while feeding it into the grid.

FYI, the LzText object has an escapeText() method built-in, not that it particularly helps the gridtext issue you are facing.

Robert
http://www.qrowd.com
http://www.cooqy.com

kbriggs
03-28-2008, 12:36 PM
Another way is to intercept the ondata event for the gridtext and manipulate the data there, if you want to manipulate the data while feeding it into the grid.


Can you give me an example of this method? Let's say my grid looks like this:


<grid width="100%" height="100%" contentdatapath="PlayerLogins:/player">
<gridtext editable="false" width="120" datapath="@Name">Player</gridtext>
<gridtext editable="false" width="150" datapath="@RealName">Name</gridtext>
<gridtext editable="false" width="180" datapath="@Location">Location</gridtext>
<gridtext editable="false" width="${parent.width-450}" datapath="@Time">Login Time</gridtext>
</grid>


And I want to escape the text displayed in the Location column. What would go in the ondata handler for it?

rcyeager
03-28-2008, 12:59 PM
If you can post a complete sample w/ a data file, I'll show how.

Robert
http://www.qrowd.com
http://www.cooqy.com

kbriggs
03-28-2008, 01:14 PM
If you can post a complete sample w/ a data file, I'll show how.

That pretty much is the complete example minus the canvas and dataset tags. The dataset is called PlayerLogins as indicated in the contentdatapath. The data looks like:

<player Name="abc" RealName="def" Location="ghi" Time="jkl">

So if I add an ondata handler for the Location:

<gridtext editable="false" width="180" datapath="@Location">Location</gridtext>
<handler name="ondata">
<!-- what goes here? -->
</handler>

rcyeager
03-28-2008, 01:47 PM
Err, a couple of problems. First, the gridtext doesn't identify its text view with a name attribute, making it hard to intercept its events without having to peek into subviews[], which would be fragile.

Instead of that, it is better to use a gridcolumn with a text control within.

Another issue, is that my suggested technique w/ ondata that I use in 3.x doesn't seem to want to work in 4.x. So, I had to use the ontext event instead as follows:


<canvas debug="true">
<debug x="135" y="250"/>

<dataset type="http" querytype="get" request="true" name="PlayerLogins" src="players.xml"/>

<grid width="100%" height="100%" contentdatapath="PlayerLogins:/dataset/player">
<gridcolumn editable="false" width="120">Player
<text datapath="@Name" resize="true" fontstyle="plain">
<handler name="ontext">
this.setAttribute("text", this.escapeText(this.data));
</handler>
</text>
</gridcolumn>
<gridtext editable="false" width="150" datapath="@RealName">Name</gridtext>
<gridtext editable="false" width="180" datapath="@Location">Location</gridtext>
<gridtext editable="false" width="${parent.width-450}" datapath="@Time">Login Time</gridtext>
</grid>
</canvas>


Using sample data:


<dataset>
<player Name="&lt;b&gt;abc&lt;/b&gt;DEF" RealName="def" Location="ghi" Time="jkl"/>
<player Name="&lt;b&gt;abc&lt;/b&gt;DEF" RealName="def" Location="ghi" Time="jkl"/>
<player Name="&lt;b&gt;abc&lt;/b&gt;DEF" RealName="def" Location="ghi" Time="jkl"/>
</dataset>


Robert
http://www.qrowd.com
http://www.cooqy.com

kbriggs
03-28-2008, 02:14 PM
<handler name="ontext">
this.setAttribute("text", this.escapeText(this.data));
</handler>



Thanks much, I'll give this a try.

kbriggs
03-29-2008, 10:05 AM
<gridcolumn editable="false" width="120">Player
<text datapath="@Name" resize="true" fontstyle="plain">
<handler name="ontext">
this.setAttribute("text", this.escapeText(this.data));
</handler>
</text>
</gridcolumn>



This is working except for one problem. The gridtext columns will automatically style the text so that when a row is selected, it'll change the color from black to white per the default style I have set. But the text in the gridcolumn doesn't do that and just remains black when selected.