PDA

View Full Version : How to dynamicly bold an item


Peter_Chea
01-16-2004, 03:55 PM
Hi, can I change the fontstyle during run time. I like to bold the selected checkboxes but was unable to do so.
<canvas debug="true">
<simplelayout axis="y"/>
<checkbox id="check1" text="test 1" fontstyle="plain">
<method event="onvalue">
<![CDATA[
if(this.value)
{
debug.write("set to bold");
this.setAttribute("fontstyle", "bold");
}
else
{
debug.write("set to plain");
this.setAttribute("fontstyle", "plain");
}
]]>
</method>
</checkbox>
<checkbox id="check2" text="test 2" fontstyle="bold">
</checkbox>
</canvas>

antun
01-19-2004, 09:52 AM
You can't set the fontstyle attribute, but you can set the text, and in the text, include the bold tag:


check1.subviews[1].setText( '<b>foo</b>' )


Remember to escape the <s and >s.

-Antun

Peter_Chea
01-19-2004, 10:45 AM
<canvas debug="true">
<simplelayout axis="y"/>
<text>
<method event="oninit">
this.setText("&lt;b&gt;bold&lt;/b&gt;");
</method>
</text>
<text>
<method event="oninit">
this.setText("&lt;u&gt;underline&lt;/u&gt;");
</method>
</text>
</canvas>

antun
01-19-2004, 10:48 AM
Try escaping the entire method with <![CDATA[ ]]> tags, and using unescaped less-than and greater-than signs.

-Antun

Peter_Chea
01-19-2004, 12:06 PM
try it already. Same result; The text doesn't show up. This is most likely a bug.

whisperstorm
01-19-2004, 12:31 PM
you could use a variation of the drop shadow code that Antun created to make a derivation of the text widget which would have 2 layers - one with normal text, one with bold text. Then you could via js swap the normal text version with the bold version -- hiding / showing views.

Peter_Chea
01-19-2004, 06:01 PM
thanks, I was trying to find an clean way to bold an selected checkbox. Looks like I have no choice but make change to the checkbox code itself.

DanKirkd
06-08-2005, 11:11 AM
What is the status on dynamically changing font styles in 3.0? This seems like a ridiculous limitation. Can someone indicate if this will ever be addressed?

Thanks,

Dan

DanMurphy
06-15-2005, 12:05 PM
I got this to work

footext.setAttribute('fontstyle','bold')