Apply formatting (bold/underline) to specific words in Alert text?

What I’m trying to do:

I have an alert which gets triggered on the press of a button within a repeating panel. Within the alert is a fairly large block of text, within which I would like to emphasize, via formatting, certain words provided by the user within an input field in the main form.

I could not find any resources addressing this in the docs/forum, so hopeful someone may know if it is possible to accomplish this.

What I’ve tried and what’s not working:

Code Sample:

result = alert(content=self.item['dump_text'],
           title="An important choice",
           large=True)
# this is a formatted code snippet.
# paste your code between ``` 

Clone link:
share a copy of your app

You can put a RichText inside the alert, or you can use alert2 defined here: Input_box() and alert2()

1 Like

Thank you. I understand how to add rich text to an alert, but where I am struggling is how to implement logic which conditionally adds bold to specific words.

If you look at the example app for input_box, the first button shows a text with bold, italic and other formatting. You can clone the app and look at the code.

If it is still not clear, please give us a little more details.

1 Like

The simplest way might be to do this

rich_text.content = rich_text.content.replace('your_word','**your_word**') #Assuming that you are using Markdown format
1 Like

You can also use the data property

template = """**{title}**

{body}
"""


def rt_alert(title, body, large=False):
    rt = RichText(content=template)
    rt.data = {"title": title, "body": body}
    return alert(rt, large=large)

1 Like

A post was split to a new topic: InputBox button return values

A post was merged into an existing topic: Alert2 button return values