Loop to change font on a table view

Questions and answers for designing and implementing forms in Servoy

Loop to change font on a table view

Postby bevil » Wed Nov 25, 2015 11:48 am

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:

Code: Select all
   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.
bevil
 
Posts: 144
Joined: Thu Oct 18, 2012 7:31 pm

Re: Loop to change font on a table view

Postby ROCLASI » Wed Nov 25, 2015 1:02 pm

Hi Bevil,

bevil wrote:
Code: Select all
   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:
Code: Select all
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.
Code: Select all
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.
Robert Ivens
ROCLASI Software Solutions / JBS Group, Partner
SAN Developer / Servoy Valued Professional / Servoy Certified Developer
Twitter: @roclasi / @servoyforge
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5243
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: Loop to change font on a table view

Postby bevil » Wed Nov 25, 2015 5:41 pm

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:

Code: Select all
   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...

:(
bevil
 
Posts: 144
Joined: Thu Oct 18, 2012 7:31 pm

Re: Loop to change font on a table view

Postby bevil » Wed Nov 25, 2015 5:47 pm

I have changed it to:

Code: Select all
   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...
bevil
 
Posts: 144
Joined: Thu Oct 18, 2012 7:31 pm

Re: Loop to change font on a table view

Postby mboegem » Wed Nov 25, 2015 6:01 pm

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...
_____________________
Marc Boegem
Solutiative / JBS Group, Partner
• Servoy Certified Developer
• Servoy Valued Professional
• Freelance SAN Developer

Image
User avatar
mboegem
 
Posts: 1395
Joined: Sun Oct 14, 2007 1:34 pm
Location: Hoofddorp, The Netherlands

Re: Loop to change font on a table view

Postby bevil » Wed Nov 25, 2015 6:16 pm

Thank you Robert. Still no joy..

I have changed to:

Code: Select all
   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).
bevil
 
Posts: 144
Joined: Thu Oct 18, 2012 7:31 pm

Re: Loop to change font on a table view

Postby ROCLASI » Wed Nov 25, 2015 6:37 pm

Hi Bevil,

That was Marc by the way ;)

Anyway, perhaps the field needs to get the focus first?
Try this:
Code: Select all
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';
}
Robert Ivens
ROCLASI Software Solutions / JBS Group, Partner
SAN Developer / Servoy Valued Professional / Servoy Certified Developer
Twitter: @roclasi / @servoyforge
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5243
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: Loop to change font on a table view

Postby bevil » Thu Nov 26, 2015 1:45 pm

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?
bevil
 
Posts: 144
Joined: Thu Oct 18, 2012 7:31 pm

Re: Loop to change font on a table view

Postby bevil » Thu Nov 26, 2015 1:47 pm

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}
bevil
 
Posts: 144
Joined: Thu Oct 18, 2012 7:31 pm

Re: Loop to change font on a table view

Postby bevil » Thu Nov 26, 2015 2:53 pm

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...
bevil
 
Posts: 144
Joined: Thu Oct 18, 2012 7:31 pm


Return to Forms

Who is online

Users browsing this forum: No registered users and 1 guest