How to change to font style of HTMl field

dvelloriy
Kilo Sage

Hi Community

 

I have an HTML field "Introduction" on knowledge form. I have set the default font style as Tahoma and font size 12 pt.

This is done by updating the dictionary default value:

<p><span style="font-family: tahoma; font-size: 12pt;">&nbsp;</span></p>

 

This is working fine on most knowledge templates but there is 1 template where we are setting some prepopulated text in this field via on load client script due to which the default style changes to Verdana and font size to 8 pt.

 

Below is the client script:

function onLoad() {
//Type appropriate comment here, and begin script below
var base = g_form.getValue('kb_knowledge_base');
var versionValue = g_form.getValue('version');

if(base == '42a1f18647dc9d50da21ebbd436d432e' && versionValue=='')
{
g_form.setValue('short_description', 'How to');
g_form.setValue('u_kb_introduction', 'This article');

}

 

is there a way to fix this font problem? i tried several ways however it does not seem to work:

 

//var element = g_form.getControl('u_kb_introduction').getElement();
var element = document.getElementById('u_kb_introduction');
// Set the font style
element.style.fontFamily = 'Tahoma';
element.style.fontSize = '12px';

 

1 ACCEPTED SOLUTION

-O-
Kilo Patron
Kilo Patron

You need to add the HTML that sets styles to the field's value, not to the control that hosts the HTML.

g_form.setValue('u_kb_introduction', '<p><span style="font-family: tahoma; font-size: 12pt;">This article</span></p>')

View solution in original post

8 REPLIES 8

-O-
Kilo Patron
Kilo Patron

You need to add the HTML that sets styles to the field's value, not to the control that hosts the HTML.

g_form.setValue('u_kb_introduction', '<p><span style="font-family: tahoma; font-size: 12pt;">This article</span></p>')

gnewuser
Tera Contributor

I have the same requirement as the OP, However when I use the set value code above, it does set the font to the correct size on the form load(since the code is on onload) but the moment when I start typing in the html field , it goes back to a different size.

What is the value that you are setting?

gnewuser
Tera Contributor

I am setting the below in form's page on load client script. 

g_form.setValue('u_kb_introduction', '<p><span style="font-family: tahoma; font-size: 12pt;">This article</span></p>')