How to get RichText of a component?


#1

I know [[This.text]] but how can i get the richtext of a component ?


#2

What do you mean by “get richtext”? Rich Text is not a property or value, but rather a collection of formatting or style properties, like font, size, color, bold/italic/underline/strikethrough, etc. Technically, I’d say it is more of a document format than any kind of thing you can “get.”

Axure lets you set certain text styles as part of its rich text option in a Set Text action. But, Axure does not support getting any of these style properties. Neither does it support directly changing any of these dynamically. So, you’ll need to “roll your own” somehow. You should be able to programmatically determine text style properties based on how you set it up in the editor–or, in a more advanced manner, determine any changes based on how you allowed those changes in your interaction code.

Do you have a specific example or more details about why you want to get or use specific text style properties? That could help forum folks brainstorm solutions. For example, a widget could set global variables when its rich text properties get loaded or changed. Or, a widget could have some associated widgets to track its style properties (maybe hidden and grouped with the widget, or in a dynamic panel but outside of that panel’s viewport.) If you use javascript injection, you could probably make things a little more efficient and functional with a combination of javascript and CSS.


#3

Thanks mbc66, I know script injection and know the coding.

I just want to find a way to make a function of highlight multiple words in pure Axure.

EXAMPLE:
There is a repeater , a column called “Column0”,
first row data: a1a2a3a4a
second row data: aaabbbcccaaabbbcccaaabbbccc
… any contains “a”

EXPECT RESULT:
“a” is red in each row.


#4

Oh, I misunderstood. I thought you meant a literal “get” instead of actually setting rich text. This has got to be easier with RegEx, which Axure doesn’t support, but you should be able to do with js injection. Here is a thread for basically injecting regex support into Axure:

Now, I’ll bet javascript calls won’t work in a repeater, as you’ll need some delay–at least 50 ms–between js calls, which you can’t do or rely on in an Item Loaded event. …But that’s just a guess. You could try calling a “listener event” row by row maybe, and set the text via js, wait a bit then process the next row.

Doing this in pure Axure could be a pain, but seems like it could maybe work if you can set up a recursive loop to set the rich text char by char. Maybe don’t use Item Loaded to set the text but instead use a “listener event” like Move and use that to trigger a function to set rich text. My idea here is a recursive loop (like change dp state every 100 ms) that tests the first char only and if an ‘a’ it calls Set Text (rich text) setting that char to red, if not set that char to black; then (loop and) test the second, etc.


#5

I tried this out and couldn’t get it to work. I don’t think there is a way in Axure to change the text value of a widget with “dynamic rich text” per string character. There would need to be a way to retain the current rich text styling of a widget and change only a portion, or substring. Setting rich text is “all or nothing” …so you can change one character or substring to a different color, but not multiple chars at random or dynamic positions. Iterative calls to Set Text (rich text) either delete previous/subsequent parts of the string, or recolor the whole string. …Maybe someone knows a solution though?

Here’s the closest I could get, a kind of brute force hack solution for your problem. The tradeoff is the string gets represented as one widget per char–with some preset or maximum string length, so it basically turns any font into a fixed-width font. If that is acceptable, this is a pretty straightforward solution. You could potentially resize the width of the widgets and move them, based on the px width of the proportional font char, in order to keep the proportional font layout.

dynamic rich text in repeater.rp (112.6 KB)

Page 1 shows the hack solution. Page 2 shows my tests and attempts to apply dynamic rich text formatting.


#6

I think in the current version, it is difficult to implement this function without injecting script. Put it aside for now.

Thanks again, you are master!


closed #7

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.