Loop to change font on a table view

I have a table view which has an RTF field which is set to Tahoma, 0, 11.

At some point this field was set to Tahoma, 0, 12, and as my customer has continued to use the solution, the lines have become mixed between 11 and 12. This manifests when they print a quote on paper, and the font sizes are slightly different, enough to make the output look incongruous.

I have manually changed every line on one quote to 11 for each of the description lines, but there were over 100 rows, and it was tedious. However it did work, therefore I would assume that a loop, and a change of the element’s font property should do the same thing.

I would like to be able to loop through all records in a given quote and set the size (just the size as some lines are intended to be bold or different colours) to a value that I would like them to be able to choose (from a dropdown whose ondatachange runs the loop for example).

I have tried a series of variations of this:

	for(var i=1; i<=foundset.getSize(); i++)
	{
	foundset.getRecord(i)
	forms.line_items_complex_master.elements.description.font.fontsize(font_size)
	}

This does nothing.

Any help would be appreciated.

Hi Bevil,

bevil:

	for(var i=1; i<=foundset.getSize(); i++)
{
foundset.getRecord(i)
forms.line_items_complex_master.elements.description.font.fontsize(font_size)
}

A couple of things:

foundset.getRecord(i)

This returns the record object of row i, it doesn’t change the selection. For that you need to use foundset.setSelectedIndex(i) or controller.setSelectedIndex(i).

Also you use foundset and then you refer to another form. Is this the same form as you are looping over the foundset from ? Or is this a related form with line items.
If there latter shouldn’t you be looping over those lines as well or do you only want to change the font size on the first row of these related records?
Also if it’s a related form why not address it over the relationship. This is much safer because them Servoy knows in what context you access this form/foundset.

The font property on a rtf field holds the following tooltip:

Gets or sets the font name, style, and size of an element. font name - the name of the font family. style - the type of the font. (plain = 0; bold = 1; italic = 2; bold-italic = 3). size - the size of the font (in points). It only returns it’s correct value if it was explicitly set.
elements.elem.font = ‘Tahoma,1,11’;

So the font property only takes a string, it doesn’t have any other functions like fontsize().
Now, I am not sure this requires that the text be selected or not to apply the new font setting.

But you could try the following code. Please fix any relation/form logic when appropriate.

for ( var i = 1 ; i <= foundset.getSize(); i++ ) {
    foundset.setSelectedIndex(i);
    forms.line_items_complex_master.elements.description.selectAll(); // maybe not required
    forms.line_items_complex_master.elements.description.font = 'Tahoma, 0, 12';
}

Hope this helps.

Thank you Robert.

Actually, I was doing setSelectedIndex(i), but changed it because I doubted myself and thought I should try getRecord(i)

Changing it back, no dice. I now have:

	for(var i=1; i<=foundset.getSize(); i++)
	{
	foundset.setSelectedIndex(i)
	forms.line_items_complex_master.elements.description.selectAll()
	forms.line_items_complex_master.elements.description.font = 'Tahoma, 0, 12';

	}

And it loops through (leaving the last line selected) but does absolutely nothing to the font.

The method is running in a form (line_items_complex_master) which has the loaded records (not through a relation) and it is looping properly, just not doing anything with the font…

:(

I have changed it to:

	for(var i=1; i<=foundset.getSize(); i++)
	{
	foundset.setSelectedIndex(i)
	forms.line_items_complex_master.elements.description.selectAll()
	application.sleep(500)
//	forms.line_items_complex_master.elements.description.font = 'Tahoma, 0, 12';

	}

And it is definitely not selecting the text in the element…

Hi Bevil,

can you give it a try by looping through the records using the controller instead of the foundset?

So:
controller.getMaxRecordIndex() instead of foundset.getSize()

and:
controller.setSelectedIndex() instead of foundset.setSelectedIndex.

using the controller you will work directly on the UI and since we’re grabbing text from the UI here…

Thank you Robert. Still no joy…

I have changed to:

	for(var i=1; i<=controller.getMaxRecordIndex(); i++)
	{
	controller.setSelectedIndex(i)
	forms.line_items_complex_master.elements.description.selectAll()
	application.sleep(500)
	forms.line_items_complex_master.elements.description.font = 'Tahoma, 0, 12';

	}

And it just selects the last record. No font changes (and during the 500ms sleep, the description text is not selected).

Hi Bevil,

That was Marc by the way ;)

Anyway, perhaps the field needs to get the focus first?
Try this:

for(var i=1; i<=controller.getMaxRecordIndex(); i++) {
    controller.setSelectedIndex(i)
    forms.line_items_complex_master.elements.description.requestFocus();
    forms.line_items_complex_master.elements.description.selectAll();
    application.sleep(500);
    forms.line_items_complex_master.elements.description.font = 'Tahoma, 0, 12';
}

ACK… Sorry Marc… I evidently cannot read…

Thank you Robert…

Seem to be making progress now, the line does get selected, and the gui dropdown changes to the correct size, but the actual size of the font does not change.

This is a RTF field, I guess the size is embedded in the rtf markup?

it says this on one of the lines that is now explicitly set to 11:

{\rtf1\ansi{\fonttbl\f0\fnil Monospaced;\f1\fnil Tahoma;}\paperw11900\paperh16840\li0\ri0\fi0\f1\fs20\i0\b\ul0\cf0 To providing Design and Draughting services for July \par\li0\ri0\fi0 17h45 at 'a395.00 an hour\fs22\b0\ul0}

I guess I need a regex to replace every fs** with my font size… However, manually editing the rtf in a text area field does not change the size…