Modify substring of field's text using pgTBObjSet() ?

Help for using specific functions

Modify substring of field's text using pgTBObjSet() ?

Postby Andy » Fri Jan 31, 2020 2:14 pm

I need to match some native Toolbook functionality that changes the color of a substring of text in a display field. The color change is in response to a User Event. It is currently done by defining the substring as a hotword. One can then set rgbStroke of text of hotword "h1" to Red, for example. Any rich text formatting other than color is preserved, as is any text scrolling position.

Toolbook Actions seem to be no help here, but it looks like pgTBObjSet can accomplish this by setting the htmlText property. I'd have the substrings pre-built in html with the appropriate colors, and concatenate them as needed to update the field's text.

Because this will be needed many times, I want to ask if there might be a better way. Besides possible flicker and a possible need to reestablish the text scroll position, it just seems like a lot of fuss compared to the implementation in native Toolbook.

Please know that I am very happy that PowerPac allows me to do this at all. I just want to make sure I am using it in the best way.
Thanks, Andy
Andy
 
Posts: 47
Joined: Tue Sep 09, 2014 3:40 pm

Re: Modify substring of field's text using pgTBObjSet() ?

Postby Clifton » Fri Jan 31, 2020 3:54 pm

I would consider the possibility of using style classes to accomplish your goal.

Consider this style sheet which defines 3 classes:
    .colorA {
    color: rgb(255, 0, 0); /* Red */
    font-size: 1.25em;
    }
    .colorB {
    color: rgb(0, 128, 0); /* Green */
    font-weight: bold;
    }
    .colorC {
    color: rgb(0, 0, 255); /* Blue */
    text-transform: uppercase;
    }
Now suppose you have a field with the following string:
    My name is <span id="userID">Andy</span>
To change the styling of the name in this string, simply use the PowerPac function userProperty():
    userProperty( "userID", "className", "colorC", "set", false, false);
Why does this work?
The PowerPac Object Referencing Engine looks for either ToolBook objects by name or any HTML element by ID.
Thus most functions can perform actions on any element on the page. This includes elements created in the area outside the ToolBook frame as well.
Here is a working example of what I'm referring to:

    As shown in this example, you are not limited to changing color. You can style anything about the element of id="userID". If you use XML documents, you can even assign mouse behavior (over, out, clicks, etc.) to the element.
The full source of the example is available for download.
Attachments
chgClasses.zip
ToolBook v11.5 file (works with any version)
(117.93 KiB) Downloaded 519 times
Clifton
Site Admin
 
Posts: 732
Joined: Tue Jan 14, 2014 1:04 am

Re: Modify substring of field's text using pgTBObjSet() ?

Postby Andy » Mon Feb 03, 2020 11:43 am

Yes, that works great and it's much cleaner code. Thanks!
Andy
 
Posts: 47
Joined: Tue Sep 09, 2014 3:40 pm


Return to Function Help

Who is online

Users browsing this forum: No registered users and 2 guests

cron