How to get red asterisk on rich text box that is required

D

Deb

Somewhere in my net travels I've seen a workaround to get a red asterisk to
appear in a rich text box like it does in other controls. Can someone
provide that information?

Thank you!
 
D

Deb

I'm not a programmer, but tried to interpret this code to mean if the field
is blank, set it to required. For me, it's just a rich text field named
Reason, so the code would be:

{
var node = XDocument.DOM.selectSingleNode("my:myFields/my:Reason")
if (node = null)
{
eventObj.ReportError(node1,"required", true);
}
}

This doesn't put a red asterisk in the field, though. Can you help?
 
G

Greg Collins [InfoPath MVP]

Your if-statement is wrong. It is currently checking to see if the node doesn't exist, and if the node doesn't exist, then add the error. If the node doesn't exist, it cannot display an error.

You need to see if the node is empty rather than not present.
 
D

Deb

Thanks, Greg. Now I have this:

function msoxd_my_Reason::OnValidate(eventObj)
{
{
var node = XDocument.DOM.selectSingleNode("my:myFields/my:Reason")
if (node != null)
{
eventObj.ReportError(node,"required", false);
}
}
}


I get the red asterisk, but when I put something in the field InfoPath draws
a red border around it as if it's got the wrong value.
 
G

Greg Collins [InfoPath MVP]

Your still checking whether the rich text field node exists, and not whether there is any content in that field...

try something like this:

var node = XDocument.DOM.selectSingleNode("my:myFields/my:Reason/*")
if (node == null)
.. . .

Note the addition of the "/*" in the select statement. This goes to the rich text field (my:Reason) and tries to select any content it has. If there is no content, then node will be null, if there is content, then node will not be null.

Previously you were checking if my:Reason was null -- essentially checking if the node even existed in the dom.

Good luck!
 
L

Lance M

Hi all,

since everything is xml, that means that everything is being stored as
strings (in the long run). What you can have is something that checks
if the node is blank:

if (node.text = "")
{
' throw your error here
}

you could also run the debugger and find out where in the node the
value is being stored (i.e. .value or .text or something else). If you
look at the data validation in infopath, and have a field that checks
to see whether it is blank or not, and you then switch to the
"expression" version of your validation it will show it comparing the
node to an empty string. --> my:fieldX != ""

Hope this helps!

Lance M.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top