Errmsg with colors

Discussions about CSEntry
Post Reply
mussabahire
Posts: 58
Joined: September 5th, 2016, 4:55 am

Errmsg with colors

Post by mussabahire »

Hello cspro users.
Is there a way we can format the error message with color?
Ex: errmsg("The EA is %v and total is:%v",EA,TOT);
And the results is like:
The EA is 11001 and total is:126
Gregory Martin
Posts: 1950
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Errmsg with colors

Post by Gregory Martin »

The default errmsg does not support coloring text. However, you can achieve this behavior if you use your own custom errmsg dialog. See here for the overview:

https://www.csprousers.org/help/CSPro/h ... %20Dialogs

The attached application demonstrates this. What I did was:

1) The dialog uses Mustache to render the message: {{message}}. Mustache will escape for HTML text in {{ }} but not in {{{ }}}, so I changed {{message}} -> {{{message}}}

2) I added an Action Invoker access token so that the dialog is allowed without prompting. See here: https://www.csprousers.org/help/CSPro/a ... token.html

3) I used HTML in the errmsg text:
errmsg("We are going to color this value in blue: <span style=\"color:blue\">%v</span>", VALUE);
Note that if you use this, anytime you use a HTML reserved character in an error message, you would need to escape it. If you don't, you could break the HTML that renders the error message. For example, for safety, this is how you would escape a < character and a text fill:
errmsg("%s, aged &lt; 12, cannot be married.", encode(NAME));
colored-errmsgs.zip
You do not have the required permissions to view the files attached to this post.
Post Reply